# GPCT-standalone 打包脚本 本项目包含多种打包方式,用于将 Python 应用程序打包为可执行文件和安装包。 ## 打包方式 ### 1. 批处理脚本 (build_package.bat) **适用场景**: Windows 环境,简单快速打包 **使用方法**: ```batch # 直接双击运行或在命令行执行 build_package.bat ``` **功能**: - 自动激活虚拟环境 - 清理旧构建文件 - 执行 PyInstaller 打包 - 复制额外资源文件 --- ### 2. Python 脚本 (build_package.py) **适用场景**: 需要更多控制和自动化 **使用方法**: ```bash # 使用系统 Python 运行 python build_package.py # 或使用虚拟环境 Python venv\Scripts\python.exe build_package.py ``` **功能**: - 完整的构建流程控制 - 自动更新版本发布时间 - 支持 NSIS 安装包生成 - 构建结果验证 --- ### 3. 手动打包步骤 如果需要手动控制打包过程: ```bash # 1. 激活虚拟环境 venv\Scripts\activate.bat # 2. 清理旧文件 rmdir /s /q dist build # 3. 执行 PyInstaller pyinstaller spec\GPCT-standalone.spec # 4. 复制额外文件 xcopy /y dataFile\config.json dist\GPCT-standalone\_internal\dataFile\ xcopy /y dataFile\data.db dist\GPCT-standalone\_internal\dataFile\ xcopy /y Syunew3D_x64.dll dist\GPCT-standalone\_internal\ xcopy /y influxd.exe dist\GPCT-standalone\_internal\ # 5. 构建 NSIS 安装包 (可选) "C:\Program Files (x86)\NSIS\makensis.exe" GPCT-standalone.nsi ``` --- ## 文件说明 | 文件 | 说明 | |------|------| | `build_package.bat` | Windows 批处理打包脚本 | | `build_package.py` | Python 自动化打包脚本 | | `spec/GPCT-standalone.spec` | PyInstaller 配置文件 | | `GPCT-standalone.nsi` | NSIS 安装包脚本 | --- ## 输出目录 打包完成后,文件将位于: ``` dist/ ├── GPCT-standalone/ # 便携版文件夹 │ ├── GPCT-standalone.exe # 主程序 │ ├── _internal/ # 依赖文件 │ │ ├── config.json │ │ ├── data.db │ │ ├── Syunew3D_x64.dll │ │ └── ... │ └── ... └── GPCT-standalone-Setup.exe # 安装包 (如果构建了 NSIS) ``` --- ## 注意事项 1. **虚拟环境**: 确保 `venv` 目录存在且包含所有依赖 2. **PyInstaller**: 需要安装 `pip install pyinstaller` 3. **NSIS**: 如需构建安装包,请安装 [NSIS](https://nsis.sourceforge.io/) 4. **版本信息**: 修改 `version.json` 更新版本号 --- ## 依赖安装 如果虚拟环境需要更新: ```bash venv\Scripts\activate.bat pip install -r requirements.txt ```