import os import sys import PyInstaller.__main__ # 获取当前操作系统 current_os = sys.platform # 设置图标文件名 icon_file = "calculator.ico" if current_os == "win32" else "calculator.icns" # PyInstaller参数 args = [ "calculator.py", "--name=现代计算器", "--onefile", "--noconsole", "--clean", f"--icon={icon_file}" if os.path.exists(icon_file) else None, ] # 过滤掉None值 args = [arg for arg in args if arg is not None] # 执行打包 PyInstaller.__main__.run(args)