fix: 添加调试模式支持

- 添加 --debug 参数生成带控制台的版本
- 便于诊断运行时错误

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
let5sne.win10
2026-02-12 23:09:03 +08:00
parent 299504c283
commit ec8c15191b

View File

@@ -2,15 +2,17 @@
""" """
打包脚本 - 将桌面程序打包成独立可执行文件 打包脚本 - 将桌面程序打包成独立可执行文件
使用方法: pip install pyinstaller && python build_exe.py 使用方法: pip install pyinstaller && python build_exe.py
调试版本: python build_exe.py --debug
""" """
import subprocess import subprocess
import sys import sys
from pathlib import Path from pathlib import Path
PROJECT_ROOT = Path(__file__).parent PROJECT_ROOT = Path(__file__).parent)
def build(): def build(debug=False):
"""使用 PyInstaller 打包""" """使用 PyInstaller 打包"""
print("正在打包,请稍候...") print("正在打包,请稍候...")
@@ -24,13 +26,17 @@ def build():
"-m", "PyInstaller", "-m", "PyInstaller",
"--name=信封信息提取系统", "--name=信封信息提取系统",
"--onefile", "--onefile",
"--windowed",
"--clean", "--clean",
"--noconfirm", "--noconfirm",
"--paths=src", "--paths=src",
"src/desktop.py",
] ]
# 调试模式:显示控制台窗口,便于查看错误
if not debug:
cmd.append("--windowed")
cmd.append("src/desktop.py")
try: try:
subprocess.run(cmd, check=True, cwd=str(PROJECT_ROOT)) subprocess.run(cmd, check=True, cwd=str(PROJECT_ROOT))
print("-" * 50) print("-" * 50)
@@ -54,4 +60,5 @@ def build():
if __name__ == "__main__": if __name__ == "__main__":
build() debug = "--debug" in sys.argv
build(debug=debug)