Files
cutThenThink/docs/BUILD.md
congsh 0ce1d71a90 build: 添加 Windows 打包方案
- 更新 PyInstaller spec 配置
- 简化 build.sh 构建脚本
- 更新 build.bat Windows 打包脚本
- 添加 docs/BUILD.md 打包说明文档

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 15:59:23 +08:00

137 lines
2.2 KiB
Markdown
Raw Permalink 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.
# CutThenThink 打包指南
## Windows 打包
### 方法一:使用批处理脚本(推荐)
```cmd
# 双击运行
build.bat
```
### 方法二:手动命令
```cmd
# 1. 安装依赖
pip install -r requirements.txt
# 2. 安装 PyInstaller
pip install pyinstaller
# 3. 构建
python -m PyInstaller CutThenThink.spec --clean
```
### 输出位置
```
dist/
└── CutThenThink/
├── CutThenThink.exe # 主程序
└── _internal/ # 运行时依赖
```
### 可选:安装 OCR 支持
```cmd
pip install -r requirements-ocr.txt
```
## Linux/macOS 打包
### 使用 Shell 脚本
```bash
# 添加执行权限
chmod +x build.sh
# 运行
./build.sh
```
### 手动命令
```bash
# 1. 安装依赖
pip install -r requirements.txt
# 2. 安装 PyInstaller
pip install pyinstaller
# 3. 构建
python -m PyInstaller CutThenThink.spec --clean
```
## 打包说明
### PyInstaller 配置
- `--onefile`: 打包成单个 EXE
- `--windowed`: 无控制台窗口
- `--upx`: 使用 UPX 压缩(减小体积)
- `--clean`: 清理旧的构建
### 包含的隐式导入
- PyQt6.QtCore
- PyQt6.QtGui
- PyQt6.QtWidgets
- yaml
### 排除的模块
- test, tests, pytest
## 首次运行配置
程序首次运行时会创建配置文件:
**Windows**: `%USERPROFILE%\.cutthenthink\config.yaml`
**Linux/macOS**: `~/.cutthenthink/config.yaml`
```yaml
upload:
provider: custom
endpoint: https://your-server.com/upload
api_key: your-api-key
auto_copy: true
screenshot:
format: png
save_path: ~/Pictures/Screenshots
hotkeys:
capture: Ctrl+Shift+A
region: Ctrl+Shift+R
upload: Ctrl+Shift+U
ocr:
enabled: false
auto_copy: false
```
## 故障排除
### PyInstaller 构建失败
1. 确保 PyInstaller 已安装:`pip list | grep pyinstaller`
2. 检查 Python 版本:需要 Python 3.8+
3. 清理缓存:删除 `build/``dist/` 目录后重试
### 运行时错误
1. 检查是否有防火墙阻止
2. 检查 OCR 功能是否可选安装
3. 查看日志文件(如果有)
## 体积优化建议
当前打包体积预估:
- 核心依赖:~50MB
- 可选 OCR+10MB
如需进一步减小体积:
1. 使用 `--exclude-module` 排除不需要的模块
2. 启用 UPX 压缩(已启用)
3. 使用虚拟环境减少依赖