Build a Standalone EXE
Package with the spec File
Run this command from the project directory that contains P4CaseSync.spec. The project imports modules dynamically, so the build needs the hidden imports declared in the spec file.
pyinstaller P4CaseSync.specThe generated executable is at dist/P4文件名大小写同步工具.exe
What the spec File Does
P4CaseSync.spec is configured for:
- Single-file packaging (
--onefile) - No console window (
--noconsole) - Hidden imports:
LoginUI,MainUI,Core - Output filename:
P4文件名大小写同步工具
To change settings such as filename or icon, edit P4CaseSync.spec:
- Rename: Find the line
name='P4文件名大小写同步工具' - Add an icon: Change
icon=Nonetoicon='icon.ico' - Show the console: Change
console=Falsetoconsole=Truefor debugging
The project uses InjectSysPath() to add module paths dynamically. PyInstaller cannot automatically identify modules under Source/UI and Source/Logic. The spec file explicitly declares these modules through hiddenimports to ensure packaging succeeds.
Packaging Options and Notes
Do not mix command-line packaging options with a spec file:
# ❌ 错误示例pyinstaller -F -w P4CaseSync.spec # 会报错
# ✅ 正确用法pyinstaller P4CaseSync.spec