build.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """
  2. PyInstaller 打包脚本
  3. 用于将日记账生成工具打包成 exe 文件
  4. """
  5. import os
  6. import subprocess
  7. import sys
  8. def build_exe():
  9. """执行打包操作"""
  10. print("=" * 50)
  11. print("开始打包日记账生成工具")
  12. print("=" * 50)
  13. pyinstaller_path = os.path.join(sys.executable, "-m")
  14. cmd = [
  15. sys.executable,
  16. "-m",
  17. "PyInstaller",
  18. "--name=日记账生成工具",
  19. "--onefile",
  20. "--windowed",
  21. "--clean",
  22. "--noconfirm",
  23. "main.py"
  24. ]
  25. print("执行命令:")
  26. print(" ".join(cmd))
  27. print()
  28. try:
  29. result = subprocess.run(cmd, check=True)
  30. print("=" * 50)
  31. print("打包完成!")
  32. print("=" * 50)
  33. print("生成的 exe 文件位于: dist/日记账生成工具.exe")
  34. return True
  35. except subprocess.CalledProcessError as e:
  36. print("=" * 50)
  37. print("打包失败!")
  38. print("=" * 50)
  39. print(f"错误代码: {e.returncode}")
  40. return False
  41. if __name__ == "__main__":
  42. build_exe()