dmMaze / BallonsTranslator

深度学习辅助漫画翻译工具, 支持一键机翻和简单的图像/文本编辑 | Yet another computer-aided comic/manga translation tool powered by deeplearning
GNU General Public License v3.0
2.53k stars 172 forks source link

linux/mac os support #8

Open imKota opened 2 years ago

imKota commented 2 years ago

Hello!

Can you make release for linux/mac os ?

dmMaze commented 2 years ago

Hello I'll build a linux excuctable for next version, however I don't have a mac so I can't provide support for mac os.
The source code should run fine on mac if python(<3.10) environment is set up: python ballontranslator/__main__.py

imKota commented 2 years ago

Thanks!

➜  python3 ballontranslator/__main__.py
[INFO   ] import_utils:<module>:50 - PyTorch version 1.11.0 available.
[INFO   ] import_utils:<module>:50 - PyTorch version 1.11.0 available.
PyTorch version 1.11.0 available.
Traceback (most recent call last):
  File "/Users/kota/Downloads/BallonsTranslator-master/ballontranslator/__main__.py", line 30, in <module>
    main()
  File "/Users/kota/Downloads/BallonsTranslator-master/ballontranslator/__main__.py", line 24, in main
    ballontrans = MainWindow(app, open_dir=args.proj_dir)
  File "/Users/kota/Downloads/BallonsTranslator-master/ballontranslator/ui/mainwindow.py", line 45, in __init__
    self.setupUi()
  File "/Users/kota/Downloads/BallonsTranslator-master/ballontranslator/ui/mainwindow.py", line 75, in setupUi
    self.setMinimumWidth(screen_size.width()*0.5)
TypeError: setMinimumWidth(self, int): argument 1 has unexpected type 'float'

I will wait for the corrections for the linux version. And then I will try to build for mac os.

If you want, i can help with mac os release.

dmMaze commented 2 years ago

line 75: explicitly convert to int type should fix this, self.setMinimumWidth(int(screen_size.width()*0.5)) Any help would be appreciated.

imKota commented 2 years ago

line 75: explicitly convert to int type should fix this, self.setMinimumWidth(int(screen_size.width()*0.5))

Yes, I know. On the weekend I will try to fix all the errors and build a release for the mac OS.

ghost commented 2 years ago

我也等一个macos版,需要的话可以帮忙在M1 pro上进行build,可能需要提供build的步骤

dmMaze commented 2 years ago

我也等一个macos版,需要的话可以帮忙在M1 pro上进行build,可能需要提供build的步骤

经提醒可以用github actions,我下礼拜试试

ghost commented 2 years ago

qt5是支持macOS的,但是我不懂Github Action的Workflow要怎么写能编译成功qt5,只会electron的workflow

dmMaze commented 2 years ago

qt5是支持macOS的,但是我不懂Github Action的Workflow要怎么写能编译成功qt5,只会electron的workflow

装了环境gitclone源码python ballontranslator/main.py应该就能跑,不需要pydensecrf,可能会有些类型错误不过改起来也简单

ghost commented 2 years ago
截屏2022-07-05 16 16 51

macOSl拉库报错,请帮忙看下是什么原因。


brew install mecab后解决上述报错,但又有新的报错了 截屏2022-07-05 16 21 51


另外,现在这个项目可以用macOS打包吗,打包过程可否指导下,谢谢!

dmMaze commented 2 years ago
截屏2022-07-05 16 16 51

macOSl拉库报错,请帮忙看下是什么原因。


brew install mecab后解决上述报错,但又有新的报错了 截屏2022-07-05 16 21 51


另外,现在这个项目可以用macOS打包吗,打包过程可否指导下,谢谢!

pyqt现在还不支持py3.10及以上

然后你还需要下载data https://drive.google.com/drive/folders/1uElIYRLNakJj-YS0Kd3r3HE-wzeEvrWd?usp=sharing 解压并覆盖BallonsTranslator/ballontranslator下的同名目录

我还没试过macos打包,貌似pytorch支持m1加速?这些我还没条件验证

ghost commented 2 years ago
Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [23 lines of output]
      Querying qmake about your Qt installation...
      Traceback (most recent call last):
        File "/Users/chenzhiyu/.pyenv/versions/3.9.13/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 156, in prepare_metadata_for_build_wheel
          hook = backend.prepare_metadata_for_build_wheel
      AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'

      During handling of the above exception, another exception occurred:

      Traceback (most recent call last):
        File "/Users/chenzhiyu/.pyenv/versions/3.9.13/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/Users/chenzhiyu/.pyenv/versions/3.9.13/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/Users/chenzhiyu/.pyenv/versions/3.9.13/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 160, in prepare_metadata_for_build_wheel
          whl_basename = backend.build_wheel(metadata_directory, config_settings)
        File "/private/var/folders/cl/wp12ygrn1cz9gkrlh8n5tls00000gn/T/pip-build-env-4uarrol2/overlay/lib/python3.9/site-packages/sipbuild/api.py", line 46, in build_wheel
          project = AbstractProject.bootstrap('wheel',
        File "/private/var/folders/cl/wp12ygrn1cz9gkrlh8n5tls00000gn/T/pip-build-env-4uarrol2/overlay/lib/python3.9/site-packages/sipbuild/abstract_project.py", line 87, in bootstrap
          project.setup(pyproject, tool, tool_description)
        File "/private/var/folders/cl/wp12ygrn1cz9gkrlh8n5tls00000gn/T/pip-build-env-4uarrol2/overlay/lib/python3.9/site-packages/sipbuild/project.py", line 600, in setup
          self.update(tool)
        File "project.py", line 160, in update
      sipbuild.exceptions.UserException
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

装了mecab、pyqt5,但拉库还是报新错,这次实在看不懂是缺了啥,请作者帮忙看看,谢谢!

dmMaze commented 2 years ago

AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'

这还是装pyqt5报的错?
https://stackoverflow.com/questions/65447314/attributeerror-module-sipbuild-api-has-no-attribute-prepare-metadata-for-bui 这里有建议升级pip, 装pyqt5前装pyqt5-sip, 还是不行就试试pyqt6

ghost commented 2 years ago

pyqt5-sip成功,但pyqt5无法安装成功,把requirements.txt里的pyqt5改成pyqt6后,pyqt6安装成功,但拉库报新错

  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/cl/wp12ygrn1cz9gkrlh8n5tls00000gn/T/pip-install-i9gf2rr9/pkuseg_24ee9a471c02433e9f375ce9c3c36cf8/setup.py", line 5, in <module>
          import numpy as np
      ModuleNotFoundError: No module named 'numpy'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
dmMaze commented 2 years ago

ModuleNotFoundError: No module named 'numpy'

pip install numpy requirements里的都装上了吗, 按理来说里面有依赖numpy会一起装的所以就没写进去

ghost commented 2 years ago

numpy安装成功,但又跳出来tokenizers无法安装成功

dmMaze commented 2 years ago

@blacklein 如果不用mangaocr(有其它ocr可选) transformers和tokenizers就不是必装 你可以注释掉这些行再跑源码 https://github.com/dmMaze/BallonsTranslator/blob/430f0321eda0f7b25ce170f5304d2fd57db7bc01/ballontranslator/dl/ocr/__init__.py#L106-L149

ghost commented 2 years ago

tokenizers安装成功了,多试几次,成功原因不明,但又跳出pkuseg安装失败,醉了

requirements.txt删除pkuseg后拉库成功没有报错,不知道这个pkuseg是否为必要

dmMaze commented 2 years ago

requirements.txt删除pkuseg后拉库成功没有报错,不知道这个pkuseg是否为必要

试试pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pkuseg-py39
这个主要是给中文分词断句的, 不装的话在设置里关掉自动分行才能用

ghost commented 2 years ago

pip3 install -i pypi.tuna.tsinghua.edu.cn/simple pkuseg-py39 这个安装失败

pip3 install spacy-pkuseg 这个安装成功,可以替代吗?介绍里写着这包是pkuseg的fork,原版是2020年,这个包是2022年的

ghost commented 2 years ago

按照下面修改过的requirements.txt拉包成功(<----表示修改或增加的包)

# To install pytorch cuda (gpu) version, please look https://pytorch.org/
urllib3==1.25.11 # https://github.com/psf/requests/issues/5740
jaconv
Mecab-python3  <----
torch
torchvision
transformers
fugashi
unidic_lite
tqdm
opencv-python==4.5.*
PyQt6  <----
numpy  <----
tokenizers  <----
shapely
pyclipper
einops
termcolor
bs4
deepl
qtpy
spacy-pkuseg  <----
sentencepiece
ctranslate2

data文件夹放入指定文件夹后,运行命令报错

❯ python3 ballontranslator/__main__.py
/Users/chenzhiyu/.pyenv/versions/3.9.12/lib/python3.9/site-packages/qtpy/__init__.py:267: RuntimeWarning: Selected binding "pyqt5" could not be found, using "pyqt6"
  warnings.warn('Selected binding "{}" could not be found, '
[INFO   ] import_utils:<module>:51 - PyTorch version 1.12.1 available.
[INFO   ] import_utils:<module>:51 - PyTorch version 1.12.1 available.
PyTorch version 1.12.1 available.
Traceback (most recent call last):
  File "/Users/chenzhiyu/Downloads/BallonsTranslator/ballontranslator/__main__.py", line 44, in <module>
    main()
  File "/Users/chenzhiyu/Downloads/BallonsTranslator/ballontranslator/__main__.py", line 23, in main
    from ui.mainwindow import MainWindow
  File "/Users/chenzhiyu/Downloads/BallonsTranslator/ballontranslator/ui/mainwindow.py", line 16, in <module>
    from .configpanel import ConfigPanel
  File "/Users/chenzhiyu/Downloads/BallonsTranslator/ballontranslator/ui/configpanel.py", line 7, in <module>
    from PyQt5 import QtCore
ImportError: cannot import name 'QtCore' from 'PyQt5' (unknown location)
dmMaze commented 2 years ago

pip3 install -i pypi.tuna.tsinghua.edu.cn/simple pkuseg-py39 这个安装失败

pip3 install spacy-pkuseg 这个安装成功,可以替代吗?介绍里写着这包是pkuseg的fork,原版是2020年,这个包是2022年的 我试了一下,把源码下面这段改成import spacy_pkuseg as pkuseg后似乎没问题(win11) https://github.com/dmMaze/BallonsTranslator/blob/430f0321eda0f7b25ce170f5304d2fd57db7bc01/ballontranslator/utils/text_processing.py#L190 注意第一次分行的时候它会下载自己的模型

ghost commented 2 years ago

按上面修改了,但仍然报错

❯ python3 __main__.py
/Users/chenzhiyu/.pyenv/versions/3.9.12/lib/python3.9/site-packages/qtpy/__init__.py:267: RuntimeWarning: Selected binding "pyqt5" could not be found, using "pyqt6"
  warnings.warn('Selected binding "{}" could not be found, '
[INFO   ] import_utils:<module>:51 - PyTorch version 1.12.1 available.
[INFO   ] import_utils:<module>:51 - PyTorch version 1.12.1 available.
PyTorch version 1.12.1 available.
Traceback (most recent call last):
  File "/Users/chenzhiyu/Downloads/BallonsTranslator/ballontranslator/__main__.py", line 44, in <module>
    main()
  File "/Users/chenzhiyu/Downloads/BallonsTranslator/ballontranslator/__main__.py", line 23, in main
    from ui.mainwindow import MainWindow
  File "/Users/chenzhiyu/Downloads/BallonsTranslator/ballontranslator/ui/mainwindow.py", line 16, in <module>
    from .configpanel import ConfigPanel
  File "/Users/chenzhiyu/Downloads/BallonsTranslator/ballontranslator/ui/configpanel.py", line 7, in <module>
    from PyQt5 import QtCore
ImportError: cannot import name 'QtCore' from 'PyQt5' (unknown location)
dmMaze commented 2 years ago

python3 ballontranslator/main.py

python3 ballontranslator/main.py --qt-api pyqt6

ghost commented 2 years ago

好像没用,还是在improt from pyqt5

❯ python3 ballontranslator/__main__.py --qt-api pyqt6
[INFO   ] import_utils:<module>:51 - PyTorch version 1.12.1 available.
[INFO   ] import_utils:<module>:51 - PyTorch version 1.12.1 available.
PyTorch version 1.12.1 available.
Traceback (most recent call last):
  File "/Users/chenzhiyu/Downloads/BallonsTranslator/ballontranslator/__main__.py", line 44, in <module>
    main()
  File "/Users/chenzhiyu/Downloads/BallonsTranslator/ballontranslator/__main__.py", line 23, in main
    from ui.mainwindow import MainWindow
  File "/Users/chenzhiyu/Downloads/BallonsTranslator/ballontranslator/ui/mainwindow.py", line 16, in <module>
    from .configpanel import ConfigPanel
  File "/Users/chenzhiyu/Downloads/BallonsTranslator/ballontranslator/ui/configpanel.py", line 7, in <module>
    from PyQt5 import QtCore
ImportError: cannot import name 'QtCore' from 'PyQt5' (unknown location)
ghost commented 2 years ago

pip安装puqt5失败,但brew install pyqt5成功,但似乎没用

dmMaze commented 2 years ago

File "/Users/chenzhiyu/Downloads/BallonsTranslator/ballontranslator/ui/configpanel.py", line 7, in from PyQt5 import QtCore

把这行(configpanel.py, line7)改成from qtpy import QtCore

ghost commented 2 years ago
截屏2022-08-21 16 55 41

我的是M1 Max Macbook Pro,成功启动项目,真是不容易,谢谢作者~还未试着翻译,稍后反馈更新

dmMaze commented 2 years ago

@blacklein qt6可能会有些坑,遇到的话请另外提issue

ghost commented 2 years ago

运行了可以正常工作,但超级吃内存,32G内存吃了20G,运行完内存占用瞬间直接从25G降到5G

后面我打算试试能不能用pyinstaller打包成macOS app,这样用起来方便,但估计应用体积会很大

ghost commented 2 years ago

pyinstaller --clean -F -w __main__.py打包macOSapp成功,但只有20MB,应该是data和requirements依赖没打包进去

打包参数用的下面,有点挠头了

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None

a = Analysis(
    ['__main__.py'],
    pathex=[],
    binaries=[],
    datas=[],
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    [],
    name='__main__',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=False,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)
app = BUNDLE(
    exe,
    name='__main__.app',
    icon=None,
    bundle_identifier=None,
)
ghost commented 2 years ago

我是不是只要把data文件夹加进去main.spec就好了?好像还是不行,缺了什么呢

dmMaze commented 2 years ago

@blacklein 以上涉及源码修改已提交 46519c30e3ef013ddaa88baf08334ff89a10c470 2b4e782a2c629d4d44450a1eb732ef28d66f8e03 我没怎么用过pyinstaller打包...可以自行搜索pyinstaller打包opencv+torch教程

ghost commented 2 years ago

@blacklein 以上涉及源码修改已提交 46519c30e3ef013ddaa88baf08334ff89a10c470 2b4e782a2c629d4d44450a1eb732ef28d66f8e03 我没怎么用过pyinstaller打包...可以自行搜索pyinstaller打包opencv+torch教程

requirements是不是也需要修改下?

dmMaze commented 2 years ago

requirements是不是也需要修改下?

改了 1ce12bfa2d552d029779ff37bd746d0836b74a88 另外如果你想继续折腾这个打包还有torch m1 加速可以邮件发我联系方式(qq或者tg)交流方便点

ghost commented 2 years ago

好的,我先自己折腾下看看

b0207191 commented 1 year ago

我在python3.7下运行报错,Google了下没找到解决方法,请问能否帮忙看看,谢谢

python ballontranslator

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root' Traceback (most recent call last): File "/root/.pyenv/versions/3.7.0/lib/python3.7/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/root/.pyenv/versions/3.7.0/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "ballontranslator/main.py", line 72, in File "ballontranslator/main.py", line 64, in main ModuleNotFoundError: No module named 'ui.mainwindow'

ghost commented 1 year ago

我在python3.7下运行报错,Google了下没找到解决方法,请问能否帮忙看看,谢谢

python ballontranslator

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root' Traceback (most recent call last): File "/root/.pyenv/versions/3.7.0/lib/python3.7/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/root/.pyenv/versions/3.7.0/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "ballontranslator/main.py", line 72, in File "ballontranslator/main.py", line 64, in main ModuleNotFoundError: No module named 'ui.mainwindow'

用python3.9试试