TellmeStpToGlb/build_exe.py
sladro ba45b855c6 feat: 添加可执行文件打包支持
- 新增CLI工具打包脚本build_exe.py,生成stp2glb.exe
- 新增Web服务打包脚本build_web_exe.py,生成stp2glb-server.exe
- 新增PyInstaller配置文件build.spec
- 更新CLAUDE.md文档添加exe打包使用说明
- 支持完全独立部署,无需Python环境

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 10:18:48 +08:00

89 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""
构建脚本 - 将项目打包成可执行文件
"""
import subprocess
import sys
import os
from pathlib import Path
def install_pyinstaller():
"""安装PyInstaller"""
print("安装PyInstaller...")
try:
subprocess.run([sys.executable, "-m", "pip", "install", "pyinstaller"],
check=True, capture_output=True)
print("✅ PyInstaller安装完成")
except subprocess.CalledProcessError as e:
print(f"❌ PyInstaller安装失败: {e}")
return False
return True
def build_exe():
"""构建可执行文件"""
print("\n开始构建可执行文件...")
# 构建命令
cmd = [
sys.executable, "-m", "PyInstaller",
"--onefile",
"--name", "stp2glb",
"--console",
"--add-data", "core;core",
"--add-data", "utils;utils",
"--hidden-import", "OCC",
"--hidden-import", "OCC.Core",
"--hidden-import", "trimesh",
"--hidden-import", "fastapi",
"--hidden-import", "uvicorn",
"--hidden-import", "pydantic",
"main.py"
]
try:
result = subprocess.run(cmd, check=True, capture_output=True, text=True)
print("✅ 构建成功!")
# 检查输出文件
exe_path = Path("dist/stp2glb.exe")
if exe_path.exists():
size_mb = exe_path.stat().st_size / (1024 * 1024)
print(f"📁 可执行文件: {exe_path.absolute()}")
print(f"📏 文件大小: {size_mb:.1f} MB")
return True
except subprocess.CalledProcessError as e:
print(f"❌ 构建失败: {e}")
if e.stdout:
print("标准输出:", e.stdout)
if e.stderr:
print("错误输出:", e.stderr)
return False
def main():
"""主函数"""
print("🔨 STP2GLB 可执行文件构建工具")
print("=" * 40)
# 检查是否已安装PyInstaller
try:
import PyInstaller
print("✅ 找到PyInstaller")
except ImportError:
if not install_pyinstaller():
sys.exit(1)
# 构建可执行文件
if build_exe():
print("\n🎉 构建完成!")
print("使用方法:")
print(" dist/stp2glb.exe input.stp output.glb")
print(" dist/stp2glb.exe --help")
else:
print("\n💥 构建失败")
sys.exit(1)
if __name__ == "__main__":
main()