我之前使用 pyinstaller 尝试将我的应用程序与 twisted 作为可执行文件,但执行时出现此错误:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/cx_Freeze/initscripts/Console.py", line 27, in <module>
exec code in m.__dict__
File "client_test.py", line 2, in <module>
File "/usr/local/lib/python2.7/dist-packages/Twisted-13.0.0-py2.7-linux-x86_64.egg/twisted/__init__.py", line 53, in <module>
_checkRequirements()
File "/usr/local/lib/python2.7/dist-packages/Twisted-13.0.0-py2.7-linux-x86_64.egg/twisted/__init__.py", line 37, in _checkRequirements
raise ImportError(required + ": no module named zope.interface.")
ImportError: Twisted requires zope.interface 3.6.0 or later: no module named zope.interface.
然后,我尝试使用 cx_freeze,但我得到了完全相同的错误,即使'namespace_packages': ['zope']
像这个例子一样使用。
从我构建可执行文件的位置,我可以打开一个 python 解释器并成功导入 zope.interface,我通过 安装它easy_install
,然后运行pip install -U zope.interface
,这没有任何效果。
这是我setup.py
的 cx_freeze:
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"excludes": ["tkinter"],
'namespace_packages':['zope'],
'append_script_to_exe':True
}
setup( name = "exetest",
version = "0.1",
description = "My first executable",
options = {"build_exe": build_exe_options},
executables = [Executable("client_test.py")])
编辑1:忘了提到我还尝试在__init__.py
下放置一个空白文件zope.interface
,但这也没有帮助。
编辑 2:使用 cx_freeze 时,在 build 文件夹的 library.zip 中,zope.interface 在那里,我认为没有任何模块丢失,但我仍然得到ImportError
这是来自 cx_freeze 的输出:
Missing modules:
? _md5 imported from hashlib
? _sha imported from hashlib
? _sha256 imported from hashlib
? _sha512 imported from hashlib
? builtins imported from zope.schema._compat
? ctypes.macholib.dyld imported from ctypes.util
? dl imported from OpenSSL
? html imported from twisted.web.server
? netbios imported from uuid
? ordereddict imported from zope.schema._compat
? queue imported from twisted.internet.threads
? twisted.python._epoll imported from twisted.internet.epollreactor
? twisted.python._initgroups imported from twisted.python.util
? urllib.parse imported from twisted.web.server
? win32wnet imported from uuid
? wsaccel.utf8validator imported from autobahn.utf8validator
? zope.i18nmessageid imported from zope.schema._messageid
? zope.testing.cleanup imported from zope.schema.vocabulary
编辑 3:这是我的可执行文件的 sys.path 输出(用 缩短..
)
['../build/exe.linux-x86_64-2.7/client_test',
'../build/exe.linux-x86_64-2.7',
'../build/exe.linux-x86_64-2.7/client_test.zip',
'../build/exe.linux-x86_64-2.7/library.zip']
这是我zope.interface
直接导入时遇到的错误:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/cx_Freeze/initscripts/Console.py", line 27, in <module>
exec code in m.__dict__
File "client_test.py", line 3, in <module>
File "/usr/local/lib/python2.7/dist-packages/zope.schema-4.3.2-py2.7.egg/zope/__init__.py", line 1, in <module>
__import__('pkg_resources').declare_namespace(__name__)
ImportError: No module named pkg_resources
在我的 cx_freeze setup.py添加pkg_resources
到我的包含后,程序运行