找不到模块 'cx_Freeze__init__
我正在尝试把我的Python项目转换成一个独立的可执行文件,这样我就可以在其他没有安装Python的服务器上运行它。
我使用的命令是:
python setup.py build > build.log
当我尝试运行生成的exe文件时,总是出现以下错误信息:
zipimport.ZipImportError: can't find module 'cx_Freeze__init__'
Fatal Python error: unable to locate initialization module
Current thread 0x00000b8c (most recent call first):
我已经尝试在setup.py
模块中定义我项目中使用的所有库,但这并没有解决问题。
我还添加了需要包含的DLL文件(具体内容可以参考这篇关于cx-freeze找不到所有依赖的帖子)。
这个项目包含以下库(通过pip list
命令得到的输出):
cx-Freeze (4.3.2)
docopt (0.6.1)
pip (1.5.4)
psutil (2.0.0)
pywin32 (218)
requests (2.2.1)
setuptools (2.2)
virtualenv (1.11.4)
WMI (1.4.9)
setup.py
的内容:
include_files=[
(r'C:\Python34\Lib\site-packages\pywin32_system32\pywintypes34.dll', 'pywintypes34.dll'),
(r'C:\Python34\Lib\site-packages\pywin32_system32\pythoncom34.dll', 'pythoncom34.dll'),]
build_exe_options = dict(
packages=['os', 'concurrent.futures', 'datetime', 'docopt', 'email.mime.text', 'configparser', 'enum',
'json', 'logging', 'psutil', 'requests', 'smtplib', 'socket', 'subprocess', 'sys', 'threading', 'time',
'wmi', 'pythoncom'],
excludes=[],
include_files=include_files)
executable = Executable(
script = 'pyWatch.py',
copyDependentFiles = True,
base = 'Console')
setup( name= "pyWatch",
version= "0.1",
options= {"build_exe": build_exe_options},
executables= [executable])
cx_freeze的输出(太大,无法直接粘贴在这里):http://pastebin.com/2c4hUSeD
非常感谢大家的帮助!
1 个回答
0
与2014年更新的cx_freeze相比,
现在有一个叫做pyinstaller的模块,它的最新版本是在2016年更新的。pyinstaller
使用起来也很简单,只需输入pyinstaller myscript.py,然后就搞定了。