7

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.this
(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.

Community
  • 1
  • 1
Zach Gates
  • 273
  • 2
  • 5
  • 11
  • 2
    This is a duplicate I think you can find the answer here http://stackoverflow.com/questions/5308760/py2exe-lxml-woes – PyNEwbie Mar 02 '14 at 20:58
  • Possible duplicate of [Py2exe lxml woes](https://stackoverflow.com/questions/5308760/py2exe-lxml-woes) – Daniel Haley Nov 19 '18 at 19:22

2 Answers2

7

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"]}}
)
Rohan Khude
  • 4,455
  • 5
  • 49
  • 47
anon582847382
  • 19,907
  • 5
  • 54
  • 57
  • 4
    Add the `lxml._elementpath` module. You can find more information on this thread: http://stackoverflow.com/questions/5308760/py2exe-lxml-woes Try and use a `setup.py` similar to the answer of that question if necessary. – anon582847382 Mar 02 '14 at 21:06
1

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

They also offer a working solution.

User
  • 23,729
  • 38
  • 124
  • 207