我的Python2.7应用程序使用matplotlib、enthought (mayavi、Python )、wxpython库。我需要将它打包到Windows上的一个可执行文件中,经过一些研究和实验,这似乎不是一项简单的任务。
到目前为止,我已经尝试了PyInstaller和bbfreeze。在这两种方法中,我都指定了隐藏的导入/包含(我可以从web上的随机信息中收集这些信息)来导入Enthought。这两种方法都设法创建了一个可执行文件(到目前为止,对于bbfreeze,我排除了应用程序的matplotlib部分),但是当我运行它时,它们都返回相同的错误:
Traceback (most recent call last):
File "<string>", line 6, in <module>
File "__main__.py", line 128, in <module>
File "__main__test__.py", line 23, in <module>
File "traitsui/api.py", line 36, in <module>
File "traitsui/editors/__init__.py", line 23, in <module>
File "traitsui/editors/api.py", line 49, in <module>
File "traitsui/editors/table_editor.py", line 37, in <module>
File "traitsui/table_filter.py", line 35, in <module>
File "traitsui/menu.py", line 128, in <module>
File "pyface/toolkit.py", line 98, in __init__
NotImplementedError: the wx pyface backend doesn't implement MenuManager我该怎么做呢?或者,是否有人有创建这样一个可执行文件的经验,并且可以推荐一个工具或方法?到目前为止,我只看到了本教程,但它使用的是py2exe,显然需要下载整个ETS --如果没有其他的尝试.
发布于 2016-04-22 14:35:51
这是对我有效的解决办法。
我试过使用to、PyInstaller、py2exe和cx_Freeze。最后,我决定使用cx_Freeze,因为它显然很受使用enthought类打包应用程序的人的欢迎。
使用cx_Freeze,我得到了类似的错误消息,如上面所示。问题在于它将必要的模块保存在"library.zip“文件中,这是包括mayavi在内的高级类有问题的地方。幸运的是,cx_Freeze允许指定"create_shared_zip": False选项,从而使源文件按原样直接复制到构建目录中,而不是在zip文件中。
此外,我还发现,include_files中必须手动包含一些Enthought文件和文件夹(对for也是如此,源:这里)。在这之后起作用了。我在下面添加我的设置文件代码,希望它有帮助。
import sys
import os
from cx_Freeze import setup, Executable
import scipy
scipy_path = os.path.dirname(scipy.__file__) #use this if you are also using scipy in your application
build_exe_options = {"packages": ["pyface.ui.wx", "tvtk.vtk_module", "tvtk.pyface.ui.wx", "matplotlib.backends.backend_tkagg"],
"excludes": ['numarray', 'IPython'],
"include_files": [("C:\\Python27\\Lib\\site-packages\\tvtk\\pyface\\images\\", "tvtk\\pyface\\images"),
("C:\\Python27\\Lib\\site-packages\\pyface\\images\\", "pyface\\images"),
("C:\\Python27\\Lib\\site-packages\\tvtk\\plugins\\scene\\preferences.ini", "tvtk\\plugins\\scene\\preferences.ini"),
("C:\\Python27\\Lib\\site-packages\\tvtk\\tvtk_classes.zip", "tvtk\\tvtk_classes.zip"),
("C:\\Python27\\Lib\\site-packages\\mayavi\\core\\lut\\pylab_luts.pkl","mayavi\\core\\lut\\pylab_luts.pkl"),
("C:\\Python27\\Lib\\site-packages\\mayavi\\preferences\\preferences.ini","mayavi\\preferences\\preferences.ini"),
("C:\\Python27\\Lib\\site-packages\\numpy\\core\\libifcoremd.dll","numpy\\core\\libifcoremd.dll"),
("C:\\Python27\\Lib\\site-packages\\numpy\\core\\libmmd.dll","numpy\\core\\libmmd.dll"),
(str(scipy_path), "scipy") #for scipy
]
,"create_shared_zip": False #to avoid creating library.zip
}
executables = [
Executable('myfile.py', targetName="myfile.exe", base=None)
]
setup(name='myfile',
version='1.0',
description='myfile',
options = {"build_exe": build_exe_options},
executables=executables
) 配置:
python 2.7
altgraph==0.9
apptools==4.3.0
bbfreeze==1.1.3
bbfreeze-loader==1.1.0
configobj==5.0.6
cx-Freeze==4.3.3
Cython==0.23.4
matplotlib==1.4.3
mayavi==4.4.3
MySQL-python==1.2.5
natgrid==0.2.1
numpy==1.10.0b1
opencv-python==2.4.12
pandas==0.16.2
pefile==1.2.10.post114
Pillow==3.1.1
plyfile==0.4
psutil==4.1.0
pyface==5.0.0
Pygments==2.0.2
pygobject==2.28.6
pygtk==2.22.0
PyInstaller==3.1
pyparsing==2.0.3
pypiwin32==219
PySide==1.2.2
python-dateutil==2.4.2
pytz==2015.4
scipy==0.16.0
six==1.9.0
subprocess32==3.2.7
traits==4.5.0
traitsui==5.0.0
transforms3d==0.2.1
VTK==6.2.0https://stackoverflow.com/questions/35561635
复制相似问题