2025年3月5日 星期三

用PyInstaller 將python打包成exe檔

1. 安裝 PyInstaller:

pip install pyinstaller

2.進入你的 Python 腳本所在的資料夾,執行 PyInstaller 命令

pyinstaller --onefile python檔名.py

3.包含圖形介面(避免黑色 Console 視窗)

pyinstaller --onefile --noconsole python檔名.py

4.加入圖示(更改 EXE 圖示)
pyinstaller --onefile --icon=app.ico python檔名.py

5.加密 Python 原始碼
pyinstaller --onefile --noconsole --key "my_secret_key" python檔名.py

6.成功打包後,PyInstaller 會建立以下目錄:
dist/ ├── python檔名.exe <-- 你的可執行檔在這裡 
build/ 
main.spec <-- 配置檔案,可用來修改打包設定



沒有留言:

張貼留言