Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the pyinstaller packaging step #446

Merged
merged 5 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,41 @@ $ python3 launch.py
![录屏2023-09-11 14 26 49](https://github.com/hyrulelinks/BallonsTranslator/assets/134026642/647c0fa0-ed37-49d6-bbf4-8a8697bc873e)

```
# 第1步:打开终端并确保当前终端窗口的Python大版本号是3.11,可以用下面的命令确认版本号
# 第1步:打开终端并确保当前终端窗口的Python大版本号是3.12,可以用下面的命令确认版本号
python3 -V
# 如果没有安装Python 3.12,可以通过Homebrew安装
brew install [email protected] [email protected]

# 第2步:克隆仓库并进入仓库工作目录
git clone -b dev https://github.com/dmMaze/BallonsTranslator.git
cd BallonsTranslator

# 第3步:创建和启用 Python 3.11 虚拟环境
# 第3步:创建和启用 Python 3.12 虚拟环境
python3 -m venv venv
source venv/bin/activate

# 第4步:安装依赖
pip3 install -r requirements.txt

# 第5步:源码运行程序,会自动下载 data 文件,每个文件在20-400MB左右,合计大约1.67GB,需要比较稳定的网络,如果下载报错,请重复运行下面的命令直至不再下载报错并启动程序
# 如果多次下载失败,也可以从 [MEGA](https://mega.nz/folder/gmhmACoD#dkVlZ2nphOkU5-2ACb5dKw) 或 [Google Drive](https://drive.google.com/drive/folders/1uElIYRLNakJj-YS0Kd3r3HE-wzeEvrWd?usp=sharing) 下载 `libs` 和 `models` 并放入 data 文件夹
# 下载完毕后运行下面的命令,如果正常运行且未报错,则继续进入打包应用程序的步骤
python3 launch.py

# 第6步:运行下面的远程脚本开始构建 macOS 应用程序(仅限 Apple Silicon 芯片的 Mac 设备),中途 sudo 命令需要输入开机密码授予权限
cd ..
curl -L https://raw.githubusercontent.com/dmMaze/BallonsTranslator/dev/scripts/macos-build-script.sh | bash
```
# 第6步:下载macos_arm64_patchmatch_libs.7z到项目根目录下的'.btrans_cache'隐藏文件夹
# 该步骤是为了防止打包好的应用程序首次启动时重新下载macos_arm64_patchmatch_libs.7z导致启动失败(大概率)
mkdir ./.btrans_cache2
curl -L https://github.com/dmMaze/PyPatchMatchInpaint/releases/download/v1.0/macos_arm64_patchmatch_libs.7z -o ./.btrans_cache/macos_arm64_patchmatch_libs.7z

# 第7步:下载微软雅黑字体并放到fonts文件夹下,该步骤为可选项,不影响打包,只影响字体报错信息

# 第8步:构建 macOS 应用程序中途 sudo 命令需要输入开机密码授予权限
# 安装打包工具pyinstaller
pip3 install pyinstaller
# 删除MacOS下特有的.DS_Store文件,这些文件可能导致打包失败(中概率)
sudo find ./ -name '.DS_Store' -delete
# 开始打包.app应用程序
sudo pyinstaller launch.spec
```
> 📌打包好的应用在`./data/BallonsTranslator/dist/BallonsTranslator.app`,将应用拖到 macOS 的应用程序文件夹即完成安装,开箱即用,不需要另外配置 Python 环境。

## 一键翻译
Expand Down
11 changes: 8 additions & 3 deletions launch.spec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import subprocess
commit_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').strip()

# 构造带提交哈希值的版本号
version = "1.3.35.dev." + commit_hash
version = "1.4.0.dev." + commit_hash

block_cipher = None

Expand All @@ -20,6 +20,7 @@ a = Analysis([
],
binaries=[],
datas=[
('.btrans_cache', './.btrans_cache'),
('config', './config'),
('data', './data'),
('doc', './doc'),
Expand All @@ -30,8 +31,10 @@ a = Analysis([
('translate', './translate'),
('ui', './ui'),
('utils', './utils'),
('venv/lib/python3.11/site-packages/spacy_pkuseg', './spacy_pkuseg'),
('venv/lib/python3.11/site-packages/torchvision', './torchvision'),
('venv/lib/python3.12/site-packages/spacy_pkuseg', './spacy_pkuseg'),
('venv/lib/python3.12/site-packages/torchvision', './torchvision'),
('venv/lib/python3.12/site-packages/translators', './translators'),
('venv/lib/python3.12/site-packages/cryptography', './cryptography'),
],
hiddenimports=[
'PyQt6',
Expand Down Expand Up @@ -62,6 +65,8 @@ a = Analysis([
'httpx',
'langdetect',
'srsly',
'execjs',
'pathos',
],
hookspath=[],
hooksconfig={},
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
PyQt6-Qt6>=6.6.2
PyQt6>=6.6.1
numpy
urllib3==1.25.11 # https://github.com/psf/requests/issues/5740
urllib3==1.25.11; sys_platform == 'win32' # https://github.com/psf/requests/issues/5740
urllib3; sys_platform == 'darwin' # fix urllib3.package.six.move module not found error
jaconv
torch
torchvision
Expand Down