- 新增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>
86 lines
2.6 KiB
Python
86 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
Web服务打包脚本 - 将FastAPI服务打包成可执行文件
|
||
"""
|
||
|
||
import subprocess
|
||
import sys
|
||
import os
|
||
from pathlib import Path
|
||
|
||
def build_web_exe():
|
||
"""构建Web服务可执行文件"""
|
||
print("\n开始构建Web服务可执行文件...")
|
||
|
||
# 构建命令
|
||
cmd = [
|
||
sys.executable, "-m", "PyInstaller",
|
||
"--onefile",
|
||
"--name", "stp2glb-server",
|
||
"--console",
|
||
"--add-data", "core;core",
|
||
"--add-data", "utils;utils",
|
||
"--add-data", "api;api",
|
||
"--add-data", "services;services",
|
||
"--hidden-import", "OCC",
|
||
"--hidden-import", "OCC.Core",
|
||
"--hidden-import", "trimesh",
|
||
"--hidden-import", "fastapi",
|
||
"--hidden-import", "uvicorn",
|
||
"--hidden-import", "pydantic",
|
||
"--hidden-import", "uvicorn.protocols.http.auto",
|
||
"--hidden-import", "uvicorn.protocols.websockets.auto",
|
||
"--hidden-import", "uvicorn.lifespan.on",
|
||
"app.py"
|
||
]
|
||
|
||
try:
|
||
result = subprocess.run(cmd, check=True, capture_output=True, text=True)
|
||
print("✅ Web服务构建成功!")
|
||
|
||
# 检查输出文件
|
||
exe_path = Path("dist/stp2glb-server.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"❌ Web服务构建失败: {e}")
|
||
if e.stdout:
|
||
print("标准输出:", e.stdout)
|
||
if e.stderr:
|
||
print("错误输出:", e.stderr)
|
||
return False
|
||
|
||
def main():
|
||
"""主函数"""
|
||
print("🌐 STP2GLB Web服务打包工具")
|
||
print("=" * 40)
|
||
|
||
# 检查是否已安装PyInstaller
|
||
try:
|
||
import PyInstaller
|
||
print("✅ 找到PyInstaller")
|
||
except ImportError:
|
||
print("❌ 未找到PyInstaller,请先运行 pip install pyinstaller")
|
||
sys.exit(1)
|
||
|
||
# 构建Web服务可执行文件
|
||
if build_web_exe():
|
||
print("\n🎉 Web服务构建完成!")
|
||
print("使用方法:")
|
||
print(" dist/stp2glb-server.exe")
|
||
print(" 访问 http://localhost:8000/docs 查看API文档")
|
||
print(" 访问 http://localhost:8000/health 进行健康检查")
|
||
print("\n📝 现在你有两个exe文件:")
|
||
print(" dist/stp2glb.exe - CLI工具")
|
||
print(" dist/stp2glb-server.exe - Web服务")
|
||
else:
|
||
print("\n💥 Web服务构建失败")
|
||
sys.exit(1)
|
||
|
||
if __name__ == "__main__":
|
||
main() |