解决依赖.egg格式的库时py2exe打包失败的问题

本文解决使用py2exe打包包含xmltodict模块的Python程序时遇到的问题,提供三种解决方案,包括修改安装方式、手动解压.egg文件及使用pyinstaller代替。

今天用py2exe打包一个python文件时,总是打包失败。运行exe时提示xmltodict的ImportError,找不到xmltodict。

Traceback (most recent call last):
  File "leon.pyo", line 8, in <module>
ImportError: No module named xmltodict

而xmltodict安装后是以egg格式存放的。

D:\Python27\Lib\site-packages\xmltodict-0.9.0-py2.7.egg

目前的py2exe无法识别.egg,总结了几个处理办法,如下:

方法一:

在安装xmltodict时运行:

python setup.py install_lib

方法二:

解压.egg文件,使py2exe能够识别,参考官网http://www.py2exe.org/index.cgi/ExeWithEggs

1. unpack zipped eggs, because I believe py2exe chokes on them when resolving dependencies
2. keep track of the top level packages in the eggs
3. add all of the files in the eggs to the data_files, so that the eggs are installed along side the main exe
4. build the exe
5. generate a new library.zip that does not include anything in the top level packages found in step 2

方法三:

不使用py2exe, 使用pyinstaller, 用pyinstaller打包时无此问题


转载于:https://my.oschina.net/leon0407/blog/266170

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值