""" PyInstaller 打包脚本 用于将日记账生成工具打包成 exe 文件 """ import os import subprocess import sys def build_exe(): """执行打包操作""" print("=" * 50) print("开始打包日记账生成工具") print("=" * 50) pyinstaller_path = os.path.join(sys.executable, "-m") cmd = [ sys.executable, "-m", "PyInstaller", "--name=日记账生成工具", "--onefile", "--windowed", "--clean", "--noconfirm", "main.py" ] print("执行命令:") print(" ".join(cmd)) print() try: result = subprocess.run(cmd, check=True) print("=" * 50) print("打包完成!") print("=" * 50) print("生成的 exe 文件位于: dist/日记账生成工具.exe") return True except subprocess.CalledProcessError as e: print("=" * 50) print("打包失败!") print("=" * 50) print(f"错误代码: {e.returncode}") return False if __name__ == "__main__": build_exe()