#!/usr/bin/env python3 """PyInstaller 打包脚本(可选)。 用法: pip install pyinstaller python3 build.py 产物:dist/DisSysTest(.exe) —— 单文件免安装,可在目标平台直接运行。 注意:需在目标平台(如 Windows)上执行,PyInstaller 不支持跨平台交叉打包。 """ import os import shutil import subprocess import sys HERE = os.path.dirname(os.path.abspath(__file__)) def main(): if shutil.which("pyinstaller") is None and not os.path.exists( os.path.join(sys.prefix, "Scripts", "pyinstaller.exe")): print("未检测到 PyInstaller,请先安装: pip install pyinstaller") return 1 cmd = [ sys.executable, "-m", "PyInstaller", "--onefile", # 单文件 "--windowed", # 无控制台窗口 "--name", "DisSysTest", "--paths", HERE, "--clean", "--noconfirm", os.path.join(HERE, "run.py"), ] subprocess.check_call(cmd) print("打包完成:dist/DisSysTest(.exe)") return 0 if __name__ == "__main__": sys.exit(main())