Smart_Report/build_exe.py
2025-04-17 14:15:10 +08:00

28 lines
682 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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')}")