I am having trouble parsing xml files using ElementTree after the python code is turned into .exe using cx_freeze.

from xml.etree import ElementTree

file1 = 'file1'
file2 = 'file2'

tree1 = ElementTree.parse(file1)
tree2 = ElementTree.parse(file2)
print 'Done'

It works fine with the .py file, but after I made an .exe using cx_freeze, it would give the error:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
    exec code in m.__dict__
  File "test1.py", line 6, in <module>
    tree1 = ElementTree.parse(file1)
  File "C:\Python27\lib\xml\etree\ElementTree.py", line 1177, in parse
    tree.parse(source, parser)
  File "C:\Python27\lib\xml\etree\ElementTree.py", line 648, in parse
    parser = XMLParser(target=TreeBuilder())
  File "C:\Python27\lib\xml\etree\ElementTree.py", line 1447, in __init__
    "No module named expat; use SimpleXMLTreeBuilder instead"
ImportError: No module named expat; use SimpleXMLTreeBuilder instead

I am using Python and cx_freeze-4.2.win32-py2.7. The same issues happens for Python 2.6 as well.

Any suggestions would be appreciated.


6 Years
Discussion Span
Last Post by veelasong

Looks like it is trying to use modules from your system, not ones from the executable.

That seems odd, shouldn't the exe be independent from the modules on my computers? would that be a bug in cx_freeze?

Edited by veelasong: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.