Why am I getting this ImportError?

这一生的挚爱 提交于 2019-12-19 09:11:17

问题


I have a tkinter app that I am compiling to an .exe via py2exe.

In the setup file, I have set it to include lxml, urllib, lxml.html, ast, and math.

When I run python setup.py py2exe in a CMD console, it compiles fine. I then go to the dist folder It has created, and run the .exe file.

When I run the .exe I get this popup window.
(source: gyazo.com)

I then procede to open the Trader.exe.log file, and the the contents say the following;

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

Included here is a copy of my setup.py file.

Please help me find the problem here. Thanks in advance.


回答1:


Looks like py2exe doesn't realize it should include the lxml._elementpath module, which is conditionally imported by lxml.etree. You can tell it to include that module explicitly with the includes keyword argument in your setup.py.

setup(
    options={'py2exe': {"includes": ["lxml._elementpath"]}}
)



回答2:


Py2exe has made documentation of this error on this page: http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules

They also offer a working solution.



来源:https://stackoverflow.com/questions/22133313/why-am-i-getting-this-importerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!