python pyinstaller 打包的简单使用
文件夹-无命令行窗口:
pyinstaller -w -D --icon="./src/image/app.ico" run.py --clean
压缩有问题
pyinstaller -w -D --icon="./src/image/app.ico" --upx="D:/Program Files/upx-3.95-win64/upx.exe" run.py
单文件打包-无命令行窗口:
pyinstaller -w -F --icon=./src/image/app.ico run.py
调试:
pyinstaller --icon=./src/image/app.ico run.py
单文件打包-有命令行窗口:
pyinstaller -F --icon=./src/image/app.ico run.py
清理编译文件:
--clean
-F, –onefile 打包成一个exe文件。
-D, –onedir 创建一个目录,包含exe文件,但会依赖很多文件(默认选项)。
-c, –console, –nowindowed 使用控制台,无界面(默认)
-w, –windowed, –noconsole 使用窗口,无控制台
-p:后面紧跟着你要指定的模块搜索路径,如果你的模块安装的路径没有被PyInstaller自动检索到的话,就需要自己指定了。
问题1:
no modle named "PyQt5.sip"
pyinstaller -F -I manage.ico yourpyfile.py --hidden-import PyQt5.sip
问题2:
此时如果直接尝试打包好像能打包成功,但是应用程序会闪退。原因是pyinstaller无法判断pyqt动态链接库的位置。解决方法:在打包时指明pyqt动态链接库的位置。
切换到要打包的.py文件所在的目录,在此路径打开命令行:
pyinstaller --paths "D:\Program Files (x86)\Python35-32\Lib\site-packages\PyQt5\Qt\bin" test.py
压缩:
下载地址:
https://upx.github.io
用法:
pyinstaller -F proxyWindow.spec --upx upx路径
pyinstaller -F proxyWindow.spec --upx=D:\Program Files\upx-3.95-win64