1、下载地址:http://www.pyinstaller.org/ 。

2、解压即用(V2.1)。注意环境变量,或者用pyinstaller.py的全路径,或者到解压目录下使用。*^_^*

3、打包命令示例:

python pyinstaller.py --onefile yourprogram.py

4、参数信息参见手册的Options 。


*** Updated 2015-12-11 ***

1、用pip安装pyinstaller3。

pip3 install pyinstaller

2、打包命令示例:

pyinstaller --onefile yourprogram.py

另外两个常用的参数:

(1)、添加图标

-i walker.ico    //添加图标

(2)、压缩可执行文件(upx)

--upx-dir UPX_DIR    //指定压缩程序(upx.exe)目录,默认当前目录


FAQ:

Q1、ImportError: DLL load failed

A1、walker遇到的情况是引用了pyd文件,而这个pyd文件依赖其他dll库,walker的解决方案是安装VC2010运行时库。


Q2、程序中用到多进程在打包时应注意些什么?

A2、在main函数中添加multiprocessing.freeze_support()语句,参考这里。


Q3、报如下几种错误:

ImportError: No module named _mssql
ImportError: No module named decimal
ImportError: No module named uuid

A3、很可能是代码中用到了pymssql模块,这时的解决步骤是:①、import decimal;②、import uuid;③、重新编译;④、拷贝_mssql.pyd到发布目录。


Q4、打包成功,运行时报如下错误:

Traceback (most recent call last):
  File "main.py", line 9, in 
ModuleNotFoundError: No module named 'sub.py'
[4100] Failed to execute script main

A4、walker 排查出的原因是 py 文件编码不一致,main.py 是 utf8 编码,sub.py 是 gbk 编码,统一成 utf8 编码后问题解决。


Q5、python 3.6,pyinstaller 3.3.1,pywinauto 0.6.4 打包问题可以参考:PyInstaller 3.3.1 does not work with Pywinauto lib import

A5、copy 如下:

Create folder comtypes/gen/ in the same folder of your test.py, 
and copy file _944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0.py and UIAutomationClient.py (under Lib/site-packages/comtypes/gen/) into this folder.
Then use pyinstaller --hidden-import comtypes.gen._944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0 --hidden-import comtypes.gen.UIAutomationClient test.py


相关阅读:

1、Python 打包可执行文件

2、Linux下安装pyinstaller用于将py文件打包生成一个可执行文件

3、pyinstaller无法在命令行运行,提示failed to create process.


*** walker * Updated 2018-04-21 ***