为什么我会收到此导入错误?

Zac*_*tes 7 python lxml py2exe importerror lxml.html

我有一个tkinter正在编译为.exevia 的应用程序py2exe

在安装文件中,我将其设置为包含lxmlurlliblxml.htmlastmath

当我python setup.py py2exe在 CMD 控制台中运行时,它编译得很好。然后我转到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
Run Code Online (Sandbox Code Playgroud)

这里包括我的文件的副本setup.py

请帮我找到这里的问题。提前致谢。

Ale*_*ton 7

看起来py2exe没有意识到它应该包含该lxml._elementpath模块,该模块是由 . 有条件导入的lxml.etreeincludes您可以告诉它使用关键字参数显式包含该模块setup.py

setup(
    options={'py2exe': {"includes": ["lxml._elementpath"]}}
)
Run Code Online (Sandbox Code Playgroud)

  • 添加“lxml._elementpath”模块。您可以在该线程上找到更多信息:http://stackoverflow.com/questions/5308760/py2exe-lxml-woes 如有必要,请尝试使用与该问题的答案类似的“setup.py”。 (4认同)