使用Chaco的py2exe Python应用程序出现错误
我有一个程序,它使用了Enthought的Chaco绘图库,并嵌入在一个用pyside(Qt4)做的图形界面里。程序还用到了numpy,不过这没关系。这个程序在多个平台上直接用Python运行得很好,但当我用py2exe创建一个win32的.exe文件时,运行这个.exe文件时出现了错误:
Traceback (most recent call last):
File "awesome_program.pyw", line 19, in <module>
File "plotwidget.pyc", line 13, in <module>
File "enable\api.pyc", line 8, in <module>
File "enable\base.pyc", line 35, in <module>
File "enable\colors.pyc", line 246, in <module>
File "traitsui\qt4\color_editor.pyc", line 21, in <module>
File "traitsui\editors\__init__.pyc", line 22, in <module>
File "traitsui\editors\api.pyc", line 29, in <module>
File "traitsui\editors\list_str_editor.pyc", line 33, in <module>
File "pyface\image_resource.pyc", line 18, in <module>
File "pyface\toolkit.pyc", line 73, in <module>
File "pyface\toolkit.pyc", line 38, in _init_toolkit
File "pyface\toolkit.pyc", line 31, in import_toolkit
ImportError: No module named init
我的setup.py文件是:
#! /usr/bin/env python
# setup_win32.py
# Create an .exe for win32 systems.
# Run this with:
# python setup_win32.py py2exe
import sys
from distutils.core import setup
import py2exe
# from cx_Freeze import setup, Executable
includes = []
includes.append("PySide.QtUiTools")
includes.append("PySide.QtXml")
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(options = {"py2exe": {"dll_excludes":["MSVCP90.dll"],
"includes": includes}},
name='awesomeprogram',
version='0.01',
description='A program to visualize stuff.',
author='John Doe',
author_email='dude@email.com',
console=[{"script": "awesome_program.pyw"}])
我对Chaco和py2exe还比较陌生,但我觉得在我的py2exe设置文件中,可能需要明确地包含Enthought套件中的某些东西?有没有人有这方面的经验?
1 个回答
3
我没有用过py2exe,但我对py2app有一些经验(我觉得这两个挺像的)。py2app在打包时常常漏掉很多Enthought/chaco的包,所以你需要在setup.py文件里手动添加这些包。以下是我做的步骤:
OPTIONS = dict(
includes = [
# The backends are dynamically imported and thus we need to
# tell py2app about them.
'kiva.*',
'enable.*',
'enable.qt4.*',
'pyface.*',
'pyface.ui.qt4.*',
'pyface.ui.qt4.action.*',
'pyface.ui.qt4.timer.*',
'pyface.ui.qt4.wizard.*',
'pyface.ui.qt4.workbench.*',
'traitsui.qt4.*',
'traitsui.qt4.extra.*',
'PyQt4.pyqtconfig',
'glob.*'],
argv_emulation = True)
setup(
app=APP,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
如果你用类似的OPTIONS(当然要把py2app
换成py2exe
,可能还要把PyQt4
换成PySide
),这样可能就能成功了。如果遇到其他的导入错误,只需把缺少的包加到包含列表里就行。