將需要打包的程序放到一個新文件夾里,在文件夾圖標上 shift +鼠標右鍵,然后選擇Open PowerShell window here,
接着輸入你想要的打包命令,如下:
pyinstaller指令的常見可選參數:
可選參數 格式舉例
功能說明
-F pyinstaller -F demo.py 只在dist中生產一個demo.exe文件 -D pyinstaller -D demo.py 默認選項,除了demo.exe外,還會在在dist中生成很多依賴文件,推薦使用 -c pyinstaller -c demo.py 默認選項,只對windows有效,使用控制台,就像編譯運行C程序后的黑色彈窗 -w pyinstaller -w demo.py 只對windows有效,不使用控制台 -p pyinstaller -p E:\python\Lib\site-packages demo.py 設置導入路徑,一般用不到 -i pyinstaller -i D:\file.icon demo.py 將file.icon設置為exe文件的圖標
上面的可選參數可以組合使用,比如pyinstaller -F -i D:\file.icon demo.py
。
能夠
from xxx import yyy
就盡量不要
import xxx
,這樣可以減少打包后的體積。