Smart_Report/build_exe.py

28 lines
682 B
Python
Raw Permalink Normal View History

2025-04-17 14:15:10 +08:00
import os
import subprocess
import shutil
# 当前目录
current_dir = os.path.dirname(os.path.abspath(__file__))
# 要打包的脚本
script_path = os.path.join(current_dir, "smart_report.py")
# 输出目录
dist_dir = os.path.join(current_dir, "dist")
# 如果dist目录已存在先删除
if os.path.exists(dist_dir):
shutil.rmtree(dist_dir)
# 使用PyInstaller打包
print("开始打包...")
subprocess.run([
"pyinstaller",
"--onefile", # 生成单个exe文件
"--name", "report", # 指定输出文件名
"--console", # 显示控制台窗口
script_path
])
print(f"打包完成,可执行文件位于: {os.path.join(dist_dir, 'report.exe')}")