Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Py2exe lxml woes

I have a wxpython application that depends on lxml and works well when running it through the python interpreter. However, when creating an exe with py2exe, I got this error

ImportError: No module named _elementpath

I then used python setup.py py2exe -p lxml and I did not get the above error but another one saying

ImportError: No module named gzip

Could anyone let me know what the problem is and how I can fix it. Also should I put any dll files like libxml2, libxslt etc in my dist folder? I searched the computer and did not find these files, so maybe they aren't needed?

Thanks.

Edit: I just tried with python setup.py py2exe -p -i gzip and the exe was created. But the exe generated does not run. I double click it and it doesn't do anything.

Here's the setup.py script i'm using

from py2exe.build_exe import py2exe
from distutils.core import setup

setup( windows=[{"script": "gui.py"}] )



Edit2: I tried using cx_freeze as an alternative , but got the same

ImportError: No module named _elementpath

error. Didn't know how to proceed after that.

like image 599
jack the lesser Avatar asked Mar 15 '11 07:03

jack the lesser


1 Answers

Py2exe allows you to specify additional packages/modules to include with the options argument to setup(), in case they are not automatically detected. The following should work:

from distutils.core import setup
import py2exe

setup(
    windows=[{'script': 'gui.py'}],
    options={
        'py2exe': 
        {
            'includes': ['lxml.etree', 'lxml._elementpath', 'gzip'],
        }
    }
)

I've also recently discovered PyInstaller, which has built-in support for a number of well-known packages, including lxml, so that might be worth a try as well.

like image 145
Steven Avatar answered Nov 04 '22 14:11

Steven