Python 将psyco与py2exe一起使用?

Python 将psyco与py2exe一起使用?,python,py2exe,psyco,Python,Py2exe,Psyco,在我的主脚本中,让我们将其命名为MyScript.py,我将其命名为: import psyco psyco.full() from distutils.core import setup import py2exe, sys, os, glob sys.argv.append('py2exe') import psyco #speed up compilation psyco.full() def find_data_files(source,target,patterns):

在我的主脚本中,让我们将其命名为MyScript.py,我将其命名为:

import psyco
psyco.full()
from distutils.core import setup
import py2exe, sys, os, glob

sys.argv.append('py2exe')

import psyco #speed up compilation
psyco.full()

def find_data_files(source,target,patterns):
    """Locates the specified data-files and returns the matches
    in a data_files compatible format.

    source is the root of the source data tree.
        Use '' or '.' for current directory.
    target is the root of the target data tree.
        Use '' or '.' for the distribution directory.
    patterns is a sequence of glob-patterns for the
        files you want to copy.
    """
    if glob.has_magic(source) or glob.has_magic(target):
        raise ValueError("Magic not allowed in src, target")
    ret = {}
    for pattern in patterns:
        pattern = os.path.join(source,pattern)
        for filename in glob.glob(pattern):
            if os.path.isfile(filename):
                targetpath = os.path.join(target,os.path.relpath(filename,source))
                path = os.path.dirname(targetpath)
                ret.setdefault(path,[]).append(filename)
    return sorted(ret.items())
setup(
    name="MyScript",
    version="1.0",
    description="a script that does something",
    author="Keelx",
    data_files=find_data_files('.','',[
        'gfx/*',
        'data/*',
    ]),
    options={'py2exe': {'bundle_files': 1,'optimize': 2}},
    windows=[{'script': "MyScript.py"}],
    zipfile=None,
)
然后我的setup.py如下所示:

import psyco
psyco.full()
from distutils.core import setup
import py2exe, sys, os, glob

sys.argv.append('py2exe')

import psyco #speed up compilation
psyco.full()

def find_data_files(source,target,patterns):
    """Locates the specified data-files and returns the matches
    in a data_files compatible format.

    source is the root of the source data tree.
        Use '' or '.' for current directory.
    target is the root of the target data tree.
        Use '' or '.' for the distribution directory.
    patterns is a sequence of glob-patterns for the
        files you want to copy.
    """
    if glob.has_magic(source) or glob.has_magic(target):
        raise ValueError("Magic not allowed in src, target")
    ret = {}
    for pattern in patterns:
        pattern = os.path.join(source,pattern)
        for filename in glob.glob(pattern):
            if os.path.isfile(filename):
                targetpath = os.path.join(target,os.path.relpath(filename,source))
                path = os.path.dirname(targetpath)
                ret.setdefault(path,[]).append(filename)
    return sorted(ret.items())
setup(
    name="MyScript",
    version="1.0",
    description="a script that does something",
    author="Keelx",
    data_files=find_data_files('.','',[
        'gfx/*',
        'data/*',
    ]),
    options={'py2exe': {'bundle_files': 1,'optimize': 2}},
    windows=[{'script': "MyScript.py"}],
    zipfile=None,
)
它创建一个“dist”文件夹,其中包含可执行文件、win9x可执行文件以及可执行文件旁边的gfx和数据文件夹。但是,当我运行它时,它会指向一个日志,其中显示:

回溯(最近一次呼叫最后一次): 文件“MyScript.py”,第16行,在 加载模块中的第82行文件“zipextimporter.pyo” 文件“psyco__init__uu.pyo”,第64行,在 WindowsError:[错误3]系统找不到指定的路径:“C:\Documents and Settings\Keelx\Desktop\MyScript Folder\dist\MyScript.exe\psyco\\u psyco.pyd”

看起来psyco模块没有被放入可执行文件中。我一直在搜索,但还没有找到一个有效的解决方案来让py2exe复制psyco

并且请不要发布类似“不要使用py2exe”的解决方案


在此,提前感谢所有能够帮助我的人。

查找py2exe错误对我来说似乎是一门艺术。 也就是说,我至少会提供一些可以尝试的东西。 我py2exe'ed了一个支持psyco的python脚本,并将其扔进了设置的includes部分。 这是您的设置与我的旧设置之间唯一不同的部分

options = {'py2exe': {'packages': [ 'IPython'],
                      'includes': ["psyco"],
                     }
          }
此外,我从未能够启用优化。它总是导致随机错误。根据我的经验,最好不要说这个。我认为是matplotlib造成了这些错误

希望这有帮助,
干杯,

是的,我试过一次,完全没有效果。你想解释一下“包”吗:[IPython']位?我在gtk应用程序中使用IPython作为开发控制台。它在那里只是为了在packages字段中有一些东西。还有另一件事要尝试的是,试着让心灵像鸡蛋一样,而不是像鸡蛋一样。我相信在我必须编译或运行win32.exe安装程序的软件包中使用easy_install会出现一些问题。