我有一个基于Twisted和PyGTK的Python应用程序。扭曲本身取决于zope.interface,我不直接导入它。
不幸的是,当我尝试运行我的应用时,错误日志中会出现以下错误:
Traceback (most recent call last):
File "tasks.py", line 4, in <module>
File "ui\__init__.pyc", line 14, in <module>
File "twisted\python\log.pyc", line 17, in <module>
ImportError: No module named zope.interface
Traceback (most recent call last):
File "tasks.py", line 4, in <module>
File "ui\__init__.pyc", line 14, in <module>
File "twisted\python\log.pyc", line 17, in <module>
ImportError: No module named zope.interface
Traceback (most recent call last):
File "tasks.py", line 4, in <module>
File "ui\__init__.pyc", line 14, in <module>
File "twisted\python\log.pyc", line 17, in <module>
ImportError: No module named zope.interface
我已尝试将zope.interface
和zope
的每个组合添加到INCLUDES
和PACKAGES
,但这样做只会让我构建时间错误:
running py2exe
*** searching for required modules ***
C:\Python26\lib\site-packages\py2exe\build_exe.py:16: DeprecationWarning: the sets module is deprecated
import sets
Traceback (most recent call last):
File "setup.py", line 75, in <module>
'gtk/*.ui'
File "C:\Python26\lib\distutils\core.py", line 152, in setup
dist.run_commands()
File "C:\Python26\lib\distutils\dist.py", line 975, in run_commands
self.run_command(cmd)
File "C:\Python26\lib\distutils\dist.py", line 995, in run_command
cmd_obj.run()
File "C:\Python26\lib\site-packages\py2exe\build_exe.py", line 243, in run
self._run()
File "C:\Python26\lib\site-packages\py2exe\build_exe.py", line 296, in _run
self.find_needed_modules(mf, required_files, required_modules)
File "C:\Python26\lib\site-packages\py2exe\build_exe.py", line 1306, in find_needed_modules
mf.import_hook(f)
File "C:\Python26\lib\site-packages\py2exe\mf.py", line 719, in import_hook
return Base.import_hook(self,name,caller,fromlist,level)
File "C:\Python26\lib\site-packages\py2exe\mf.py", line 136, in import_hook
q, tail = self.find_head_package(parent, name)
File "C:\Python26\lib\site-packages\py2exe\mf.py", line 204, in find_head_package
raise ImportError, "No module named " + qname
ImportError: No module named zope
我的setup.py
是:
from distutils.core import setup
import py2exe
def find_data_files(source,target,patterns):
# I've elided this, I doubt it's relevant to the problem
# ...
INCLUDES = [
'cairo',
'pango',
'pangocairo',
'atk',
'gobject',
'gio',
]
PACKAGES = [
'encodings',
]
setup(
name = 'MyApp',
description = 'My Application',
version = '1.0',
windows = [
{
'script': os.path.join('ui','tasks.py'),
'icon_resources': [
(1, os.path.join(
'ui','data','iconpack.ico'))
],
}
],
options = {
'py2exe': {
'packages': ','.join(PACKAGES),
'includes': ','.join(INCLUDES),
}
},
data_files = find_data_files(
'ui', 'ui', [
'data/*',
'gtk/*.ui'
])
)
如何让py2exe构建它?
答案 0 :(得分:23)
我不知道你是否曾经解决这个问题,或者它是否与你相关,但对于未来的搜索者,我找到了一种简单的方法来解决zope导入问题here。
具体来说,将空__init__.py
文件添加到PYTHONDIR/Lib/site-packages/zope
目录。
我使用此安装文件使用twisted
应用程序对此进行了测试:
#!/usr/bin/env python
'''
File: setup.py
Author: Spencer Rathbun
Date: 07/24/2012
Description: Setup file for py2exe, converts client python script into executable.
'''
from distutils.core import setup
import py2exe
INCLUDES = [
''
]
PACKAGES = [
'twisted'
]
setup(
name = 'client',
description = '',
version = '1.0',
console = [
{"script":"client.py",
"icon_resources":[
(1, "c:\python27\DLLs\py.ico")
]
}
],
zipfile = None,
options = {"py2exe":
{"compressed": 1,
"optimize": 1,
"ascii": 0,
"bundle_files": 1,
"packages": ','.join(PACKAGES),
"includes": ','.join(INCLUDES),
}
}
)
Py2exe现在可以使用它成功创建一个可扭曲的可执行文件,因为它依赖于zope。
答案 1 :(得分:5)
我和zope.interface
和朋友(zope.component,等)有同样的问题。具体而言,py2exe
如何搜索并发现包 AND 如何安装zope
包是一个问题。
zope
是一个名称空间包,因此它依赖于.pth
文件中的一些时髦导入逻辑(参见zope.interface-3.*.*-py2.*-nspkg.pth
),以便将它的子包添加到python的路径中。在site-packages
中查看它,你会明白我的意思。
py2exe
在“发现”此类软件包时遇到了问题。
最后,我所做的是手动将我正在使用的各种zope
软件包重新打包到site-packages
中的标准模块设置中,然后重新py2exe
- 然后发现一切都没有问题。它是一个PITA,但在py2exe
能够处理包装边缘情况和/或zope
包以py2exe
友好的方式打包之前,它就是你能做的最好的。
答案 2 :(得分:3)
我在使用Windows XP SP3中的py2exe创建包时遇到了这个问题。我发现py2exe没有正确地确定依赖关系。
要解决此问题,我卸载了我的第三方软件包,并使用以下easy_install命令安装它们
easy_install -Z <your_package_name>
-Z选项解压缩包详细信息,因此内容不会被压缩。现在运行py2exe时,它将正确检测依赖项。
希望这有帮助!