天天看點

python pyinstaller 打包的簡單使用

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