我用之前pyinstaller試着和扭曲讓我的應用程序的可執行文件,但我得到執行時,這個錯誤:導入錯誤與cx_Freeze和pyinstaller
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']
像this example.
從哪裏我建立可執行文件,即使,我可以打開一個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
加入pkg_resources
我在我的cx_freeze setup.py包括後,程序運行起來
如果你添加''packages':['zope.interface']'到你的'build_exe_options'中怎麼辦? –
已經嘗試過,同樣的確切錯誤。我甚至同時將它添加到'includes'和'namespace_packages'中。 –
它是否安裝在.egg目錄中? cx_Freeze有時在找到蛋中的東西時遇到了困難(儘管它似乎發現了扭曲)。 –