Py2exe lxml 问题

发布于 2024-10-22 16:11:32 字数 796 浏览 2 评论 0原文

我有一个 wxpython 应用程序,它依赖于 lxml,并且在通过 python 解释器运行时运行良好。但是,当使用 py2exe 创建 exe 时,我收到此错误

ImportError: No module named _elementpath

,然后我使用 python setup.py py2exe -p lxml ,但没有收到上述错误 另一位说

ImportError: No module named gzip

谁能让我知道问题是什么以及如何解决它。我还应该放任何 我的 dist 文件夹中是否有 libxml2、libxslt 等 dll 文件?我搜了一下电脑 并且没有找到这些文件,所以也许不需要它们?

谢谢。

编辑:我刚刚尝试使用 python setup.py py2exe -p -i gzip 并创建了 exe。但生成的exe无法运行。我双击它,但它没有执行任何操作。

setup.py 脚本

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

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

这是我正在使用的

Edit2:我尝试使用 cx_freeze 作为替代方案,但遇到了相同的

ImportError: No module named _elementpath

错误。之后不知道如何进行。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黎歌 2024-10-29 16:11:32

Py2exe 允许您指定其他包/模块,以包含在 setup()options 参数中,以防它们未被自动检测到。以下内容应该有效:

from distutils.core import setup
import py2exe

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

我最近还发现了 PyInstaller,它内置了对许多良好的支持- 已知的软件包,包括 lxml,因此也值得一试。

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.

末が日狂欢 2024-10-29 16:11:32

有时,修改 setup.py 文件后,您需要执行更多操作。

此处所述,
如果该软件包安装在“eggs”存档上,则需要卸载该软件包。
然后通过强制 easy_install 使用“-Z”选项解压缩存档来再次安装它,如下所示(我遇到了 paramiko 包的问题):

pip uninstall paramiko
easy_install -Z paramiko

Sometimes you will need to do another action more after modify the setup.py file.

As described here,
it should be necessary to uninstall the package if it is installed on "eggs" archive.
Then install it again by forcing easy_install to dezip the archive with the "-Z" option as following (I had the issue with paramiko package):

pip uninstall paramiko
easy_install -Z paramiko
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文