pip install pyinstaller
import sys
from PyQt5.QtWidgets import QApplication, QLabel
app = QApplication(sys.argv)
label = QLabel("Hello PyInstaller!")
label.show()
sys.exit(app.exec_())
pyinstaller --onefile --windowed --icon=app.ico main.py
# --onefile: 產生單一 exe
# --windowed: 隱藏控制台 (GUI 程序必須)
# --icon: 設置圖標
dist/main.exe 可直接雙擊運行。--hidden-import=module_name 或編寫 .spec 文件精確控制。--add-data "images;images" (Windows 分號分隔)。--upx-dir=... 或排除不需模塊。