2026-02-12 10:14:10 +08:00
|
|
|
|
# CutThenThink 打包指南
|
|
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
## Windows 打包
|
2026-02-12 10:14:10 +08:00
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
### 方法一:使用批处理脚本(推荐)
|
2026-02-12 10:14:10 +08:00
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
```cmd
|
|
|
|
|
|
# 双击运行
|
|
|
|
|
|
build.bat
|
2026-02-12 10:14:10 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
### 方法二:手动命令
|
2026-02-12 10:14:10 +08:00
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
```cmd
|
|
|
|
|
|
# 1. 安装依赖
|
|
|
|
|
|
pip install -r requirements.txt
|
2026-02-12 10:14:10 +08:00
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
# 2. 安装 PyInstaller
|
|
|
|
|
|
pip install pyinstaller
|
2026-02-12 10:14:10 +08:00
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
# 3. 构建
|
|
|
|
|
|
python -m PyInstaller CutThenThink.spec --clean
|
|
|
|
|
|
```
|
2026-02-12 10:14:10 +08:00
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
### 输出位置
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
dist/
|
|
|
|
|
|
└── CutThenThink/
|
|
|
|
|
|
├── CutThenThink.exe # 主程序
|
|
|
|
|
|
└── _internal/ # 运行时依赖
|
2026-02-12 10:14:10 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
### 可选:安装 OCR 支持
|
2026-02-12 10:14:10 +08:00
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
```cmd
|
|
|
|
|
|
pip install -r requirements-ocr.txt
|
2026-02-12 10:14:10 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
## Linux/macOS 打包
|
|
|
|
|
|
|
|
|
|
|
|
### 使用 Shell 脚本
|
2026-02-12 10:14:10 +08:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-02-12 15:59:23 +08:00
|
|
|
|
# 添加执行权限
|
|
|
|
|
|
chmod +x build.sh
|
|
|
|
|
|
|
|
|
|
|
|
# 运行
|
|
|
|
|
|
./build.sh
|
2026-02-12 10:14:10 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
### 手动命令
|
2026-02-12 10:14:10 +08:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-02-12 15:59:23 +08:00
|
|
|
|
# 1. 安装依赖
|
|
|
|
|
|
pip install -r requirements.txt
|
|
|
|
|
|
|
|
|
|
|
|
# 2. 安装 PyInstaller
|
|
|
|
|
|
pip install pyinstaller
|
|
|
|
|
|
|
|
|
|
|
|
# 3. 构建
|
|
|
|
|
|
python -m PyInstaller CutThenThink.spec --clean
|
2026-02-12 10:14:10 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
## 打包说明
|
|
|
|
|
|
|
|
|
|
|
|
### 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 构建失败
|
2026-02-12 10:14:10 +08:00
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
1. 确保 PyInstaller 已安装:`pip list | grep pyinstaller`
|
|
|
|
|
|
2. 检查 Python 版本:需要 Python 3.8+
|
|
|
|
|
|
3. 清理缓存:删除 `build/` 和 `dist/` 目录后重试
|
2026-02-12 10:14:10 +08:00
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
### 运行时错误
|
2026-02-12 10:14:10 +08:00
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
1. 检查是否有防火墙阻止
|
|
|
|
|
|
2. 检查 OCR 功能是否可选安装
|
|
|
|
|
|
3. 查看日志文件(如果有)
|
2026-02-12 10:14:10 +08:00
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
## 体积优化建议
|
2026-02-12 10:14:10 +08:00
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
当前打包体积预估:
|
|
|
|
|
|
- 核心依赖:~50MB
|
|
|
|
|
|
- 可选 OCR:+10MB
|
2026-02-12 10:14:10 +08:00
|
|
|
|
|
2026-02-12 15:59:23 +08:00
|
|
|
|
如需进一步减小体积:
|
|
|
|
|
|
1. 使用 `--exclude-module` 排除不需要的模块
|
|
|
|
|
|
2. 启用 UPX 压缩(已启用)
|
|
|
|
|
|
3. 使用虚拟环境减少依赖
|