让 py2exe 与 zope.interface 一起使用
我有一个基于 Twisted 和 PyGTK 的 Python 应用程序。 Twisted本身依赖于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 来构建这个?
I have a Python app based on Twisted and PyGTK. Twisted itself depends on zope.interface, and I don't import it directly.
Unfortunately, when I try to run my app, the following error ends up in the error log:
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
I've tried adding every combination of zope.interface
and zope
to INCLUDES
and PACKAGES
, but doing so only gives me this build time error:
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
My setup.py
is:
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'
])
)
How do I get py2exe to build this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道你是否解决过这个问题,或者它是否与你相关,但对于未来的搜索者,我找到了一种简单的方法来解决 zope 导入问题 此处。
具体来说,将空的 __init__.py 文件添加到 PYTHONDIR/Lib/site-packages/zope 目录中。
我使用
twisted
应用程序并使用此安装文件对此进行了测试:Py2exe 现在可以使用它成功地为twisted 创建可执行文件,因为它依赖于 zope。
I don't know if you ever solved this, or if it's even relevant to you anymore, but for future searchers, I found an easy way to fix the zope import problem here.
Specifically, add an empty
__init__.py
file to thePYTHONDIR/Lib/site-packages/zope
directory.I tested this with a
twisted
application, using this setup file:Py2exe can use this to successfully create an executable for twisted now, since it depends upon zope.
我对
zope.interface
和朋友(zope.component 等)也遇到了同样的问题。具体来说,这是py2exe
如何搜索和发现包以及如何安装zope
包的问题。zope
是一个命名空间包,因此依赖于其.pth
文件中的一些时髦的导入逻辑(请参阅zope.interface-3.*.*-py2 .*-nspkg.pth
),以便将其子包添加到 python 的路径中。在site-packages
中查看它,您就会明白我的意思。py2exe
在“发现”此类包时遇到问题。最后,我所做的就是手动将我使用的各种
zope
包重新打包到site-packages
中的标准模块设置中,然后重新运行py2exe
——这才发现一切都没有问题。它是一个 PITA,但在py2exe
能够处理打包边缘情况和/或zope
包以py2exe
友好的方式打包之前,它是关于你能做到的最好的事情。I've had this same problem with
zope.interface
and friends (zope.component, et al). Specifically it is a problem with howpy2exe
searches and discovers packages AND how thezope
packages are installed.zope
is a namespace package and as a result relies on some funky import logic in it's.pth
files (seezope.interface-3.*.*-py2.*-nspkg.pth
) in order to add it's sub-packages to python's path. Have a look at it insite-packages
and you'll see what I mean.py2exe
has problems "discovering" this kind of package.In the end what I did was manually repackage the various
zope
packages I was using into a stardard module setup insite-packages
and then reranpy2exe
- which then discovered everything no problem. It's a PITA, but untilpy2exe
is able to handle packaging edge cases and/or thezope
packages are packaged in apy2exe
friendly fashion, it's about the best you can do.我在 Windows XP SP3 中使用 py2exe 创建包时遇到了这个问题。我发现 py2exe 没有正确确定依赖关系。
为了解决这个问题,我卸载了第三方软件包并使用以下 easy_install 命令安装它们
easy_install -Z
-Z 选项解压缩包详细信息,因此内容不会被压缩。当您现在运行 py2exe 时,它将正确检测依赖项。
希望这有帮助!
I was facing this issue in creating a package using py2exe in Windows XP SP3. I figured out that py2exe was not determining the dependencies correctly.
To solve this issue, I uninstalled my third party package(s) and installed them using following easy_install command
easy_install -Z <your_package_name>
The -Z option unzips the package details, and hence the content is not compressed. When you run py2exe now, it will correctly detect the dependencies.
Hope this helps!