今天用py2exe打包一個python文件時,老是打包失敗。運行exe時提示xmltodict的ImportError,找不到xmltodict。python
Traceback (most recent call last): File "leon.pyo", line 8, in <module> ImportError: No module named xmltodict
而xmltodict安裝後是以egg格式存放的。ide
D:\Python27\Lib\site-packages\xmltodict-0.9.0-py2.7.egg
目前的py2exe沒法識別.egg,總結了幾個處理辦法,以下:ui
方法一:code
在安裝xmltodict時運行:xml
python setup.py install_lib
方法二:ip
解壓.egg文件,使py2exe可以識別,參考官網http://www.py2exe.org/index.cgi/ExeWithEggsci
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
方法三:get
不使用py2exe, 使用pyinstaller, 用pyinstaller打包時無此問題
it