Python 程序打包 – 使用pyinstaller
1、安装 pyinstaller
pip 安装:打开cmd输入
pip3 install pyinstaller
2、cmd 使用 pyinstaller
打包程序: 打开 cmd 输入
# pyinstaller + 所需打包的文件路径
pyinstaller E:\test.py
执行命令后,在cmd的当前目录下生成build和dist两个文件夹。
build 文件:是打包过程的临时文件,可以删除
dist 文件:这是存放打包完成的 .exe 和 程序用到的各种动态链接库文件 .dll。如果想在别的电脑运行必须copy整个文件夹,而不只是 .exe。
可选参数:
-F :打包后在 dist 文件夹中只有单个可执行文件,动态库也直接包含在 .exe 中。只要.exe文件即可运行程序。
pyinstaller -F E:\test.py
-i / –icon:给程序添加图标,注意图标是 .ico 格式。
pyinstaller -i="E:\test.ico" E:\test.py
-w:运行程序时只有GUI窗口,没有控制台窗口。
pyinstaller -w E:\test.py
-h:查看 pyinstaller 所有的可选参数。
pyinstaller -h
-d:编译为debug模式,获取运行中的日志信息
–distpath:指定生成的exe存放的目录
–workpath:指定编译中临时文件存放的目录
-clean:清理编译时临时文件
-c:使用控制台
-version-file:添加exe版本信息
3、打包 qt 程序
出现 no module name PyQt5.sip
在程序中添加
from PyQt5 import sip
也可以使用 pyinstaller 的 hiddenimports 参数