我有一个 tkinter
应用程序,我正在通过 py2exe
编译成一个 .exe
。
在设置文件中,我设置了包含lxml
、urllib
、lxml.html
、ast
和数学
。
当我在 CMD 控制台中运行 python setup.py py2exe
时,编译正常。然后我转到它创建的 dist
文件夹,并运行 .exe
文件。
当我运行 .exe
时,我得到了这个弹出窗口。
(来源:gyazo.com)
然后我继续打开 Trader.exe.log
文件,内容如下;
Traceback (most recent call last):
File "Trader.py", line 1, in <module>
File "lxml\html\__init__.pyc", line 42, in <module>
File "lxml\etree.pyc", line 12, in <module>
File "lxml\etree.pyc", line 10, in __load
File "lxml.etree.pyx", line 84, in init lxml.etree (src\lxml\lxml.etree.c:190292)
ImportError: cannot import name _elementpath
包括here是我的 setup.py
文件的副本。
请帮我找出问题所在。提前致谢。
最佳答案
看起来 py2exe
没有意识到它应该包含 lxml._elementpath
模块,该模块由 lxml.etree
有条件地导入。您可以告诉它在您的 setup.py
中使用 includes
关键字参数显式包含该模块。
setup(
options={'py2exe': {"includes": ["lxml._elementpath"]}}
)
关于python - 为什么我会收到此 ImportError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22133313/