2013-07-08 73 views
3

我用之前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包括后,程序运行起来

+0

如果你添加''packages':['zope.interface']'到你的'build_exe_options'中怎么办? –

+0

已经尝试过,同样的确切错误。我甚至同时将它添加到'includes'和'namespace_packages'中。 –

+0

它是否安装在.egg目录中? cx_Freeze有时在找到蛋中的东西时遇到了困难(尽管它似乎发现了扭曲)。 –

回答

5

pkg_resources添加到您的includes您的setup.py中,用于cx_Freeze。

+1

对于.spec文件中的PyInstaller,在'hiddenimports'列表中放置'pkg_resouces'。 –

0

尝试增加以build_exe_options一个具体包括该分包即"includes": ["zope.interface"],这应该强制包含它。

+0

谢谢,但是这个问题在评论中提到,我已经试过了。 –

0

当我添加“通过pkg_resources”中包括并运行cx_freeze剧本,我只得到这些前两行,并留在了这里:

运行建立

运行build_exe

+0

有人有同样的问题? – Maxi

+0

其实它是来自这个:namespace_packages = ['zope'] – Maxi

+0

我在包含中添加了它,它现在生成,但我尝试运行时遇到运行时错误: – Maxi

2

我有同样的问题与cx_freeze。上述解决方案似乎都不适用于我的案例。 对我来说,从here这个解决方案工作:

您需要实际创建 zope/__init__.py一个空文件,以便正常处理 由小鬼执行。find_module()实际上工作