一、背景之工具/版本
- 安裝環境:Windows7 64bit
- 使用版本Python3.6(需安裝pyinstaller)
- PyQt5
二、pyinstaller安裝
打開cmd,輸入pip install pyinstaller,回車,即可安裝。(Anaconda環境使用:conda install pyinstaller 命令進行安裝)。
常用參數說明(pyinstaller -h 來查看參數):
--icon=圖標路徑
--noconsole執行生成的exe文件時,不顯示控制檯。
-F 打包成一個exe文件
-w 使用窗口,無控制檯
-c 使用控制檯,無窗口
-D 創建一個目錄,裏面包含exe以及其他一些依賴性文件
三、pyinstaller使用
1、打開項目目錄(若您用的是Eric+PyQt開發,則此目錄會有 *.e4p文件)按住shift點擊鼠標右鍵,選擇在此處打開命令窗口。
2、輸入如下打包命令:
pyinstaller -F --icon=favicon.ico test.py --noconsole
即可打包成功,當前目錄下會生成dist文件夾,包含目標exe文件。