我正在尝试用 py2exe 打包我的程序。它使用特征 GUI。
将函数“convert_image”中 image.py 中的 import 语句移出 try 块后,装箱的 exe 在以下第二点失败:
1:dist\traitsui\ui_traits.py:从 .image.image 导入 ImageLibrary
2:dist\traitsui\image\image.py:从 traitsui.ui_traits 导入 HasBorder、HasMargin、Alignment
文件结构:
root
+-...
+-main.py
+-setup.py
+-dist
+-...
+-main.exe
+-traitsui
+-...
+-ui_tratis.py
+-image
+-image.py
通过将以下内容添加到 image.py
import sys
raise Exception(str(sys.path))
我得到: 异常:['C:\Users...\dist\.']
所以看来路径设置正确。
错误跟踪:
Traceback (most recent call last):
File "main.py", line 8, in <module>
File "gui\FileSelect.pyc", line 8, in <module>
File "traitsui\api.pyc", line 27, in <module>
File "traitsui\basic_editor_factory.pyc", line 30, in <module>
File "traitsui\editor_factory.pyc", line 32, in <module>
File "traitsui\helper.pyc", line 32, in <module>
File "C:\Users\...\dist\.\traitsui\ui_traits.py", line 158, in <module>
from .image.image import ImageLibrary
File "C:\Users\...\dist\.\traitsui\image\image.py", line 34, in <module>
from traitsui.ui_traits import HasBorder, HasMargin, Alignment
ImportError: cannot import name HasBorder
setup.py:https://gist.github.com/2570888 _