Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

python - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...