2

After building my executable with CX_Freeze and trying to run the .exe I get this error. I understand this means CxFreeze is not recognizing lxml. However I have tried to include this in my setup.py

Traceback(most recent call last):
   File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py",
line 27, in <module>
    exec(code, m._dict_)
   File "mainFile.py", line 2, in <module>
   File "C:\Users\user\TestFile\testPyQt.py",line 11, in
  <module>
     import myFile
   File "C:\Users\user\TestFile\myFile.py", line 4, in 
  <module>
    from lxml import etree
   File "ExtensionLoader_lxml_etree.py", line 22, in <module>
   File "ExtensionLoader_lxml_etree.py", line 14, in _bootstrap_
   file "lxml.etree.pyx", line 84, in init lxml.etree
  (src\lxml\lxml.etree.c:191837)
   ImportError:cannot import name_elementpath

My setup.py has this:

INCLUDE_MODULES = [

    'lxml',
    'xml.etree.ElementTree',
    'xml.etree.ElementPath',
    'libxml2'
]
sudobangbang
  • 1,406
  • 10
  • 32
  • 55

2 Answers2

3

It looks a little like the error message is missing a space. I'm pretty sure it is complaining that `lxml._elementpath' cannot be imported. This is because that module is conditionally imported by lxml.

The solution is to add lxml._elementpath to your list of INCLUDE_MODULES.

Note, this solution effectively comes from these sources, where people had similar problems with py2exe or other packages with cx_freeze:

Why am I getting this ImportError?

cx_Freeze ImportError: cannot import name

Community
  • 1
  • 1
three_pineapples
  • 11,579
  • 5
  • 38
  • 75
0

what helped in my case was the solution ThomasK pointed at above: i jsut went to python\site-packages\lxml and copied the whole folder to the \dist folder where cxfreeze copies all the other files to.

of course this is no fix of the problem itself, by a practical solution.

S. Weber
  • 53
  • 5