Byaidu / PDFMathTranslate

PDF scientific paper translation with preserved formats - 基于 AI 完整保留排版的 PDF 文档全文双语翻译,支持 Google/DeepL/Ollama/OpenAI 等服务,提供 CLI/GUI/Docker
https://pdf2zh.com
GNU Affero General Public License v3.0
2.91k stars 208 forks source link

包好像有兼容性问题 #29

Closed yansheng836 closed 1 week ago

yansheng836 commented 1 week ago

1.Python版本问题

首先是这里只说了Require Python version <=3.12,但是实际上需要3.8以上,不然有依赖会报错:

$ pip install pdf2zh==1.6.9
Collecting pdf2zh==1.6.9
  Using cached pdf2zh-1.6.9-py3-none-any.whl.metadata (4.7 kB)
Requirement already satisfied: charset-normalizer in f:\python\python37\lib\site-packages (from pdf2
zh==1.6.9) (2.0.12)
Requirement already satisfied: cryptography in f:\python\python37\lib\site-packages (from pdf2zh==1.
6.9) (38.0.1)
Requirement already satisfied: requests in f:\python\python37\lib\site-packages (from pdf2zh==1.6.9)
 (2.26.0)
Collecting pymupdf (from pdf2zh==1.6.9)
  Using cached PyMuPDF-1.22.5-cp37-cp37m-win_amd64.whl.metadata (8.5 kB)
Collecting tqdm (from pdf2zh==1.6.9)
  Using cached tqdm-4.67.0-py3-none-any.whl.metadata (57 kB)
Collecting tenacity (from pdf2zh==1.6.9)
  Using cached tenacity-8.2.3-py3-none-any.whl.metadata (1.0 kB)
INFO: pip is looking at multiple versions of pdf2zh to determine which version is compatible with ot
her requirements. This could take a while.
ERROR: Ignored the following versions that require a different python version: 0.0.2 Requires-Python
 >=3.8; 1.23.0 Requires-Python >=3.8; 1.23.0rc1 Requires-Python >=3.8; 1.23.0rc2 Requires-Python >=3
.8; 1.23.1 Requires-Python >=3.8; 1.23.10 Requires-Python >=3.8; 1.23.11 Requires-Python >=3.8; 1.23
.12 Requires-Python >=3.8; 1.23.13 Requires-Python >=3.8; 1.23.14 Requires-Python >=3.8; 1.23.15 Req
uires-Python >=3.8; 1.23.16 Requires-Python >=3.8; 1.23.18 Requires-Python >=3.8; 1.23.19 Requires-P
ython >=3.8; 1.23.2 Requires-Python >=3.8; 1.23.20 Requires-Python >=3.8; 1.23.21 Requires-Python >=
3.8; 1.23.22 Requires-Python >=3.8; 1.23.23 Requires-Python >=3.8; 1.23.24 Requires-Python >=3.8; 1.
23.25 Requires-Python >=3.8; 1.23.26 Requires-Python >=3.8; 1.23.2rc1 Requires-Python >=3.8; 1.23.3
Requires-Python >=3.8; 1.23.4 Requires-Python >=3.8; 1.23.5 Requires-Python >=3.8; 1.23.6 Requires-P
ython >=3.8; 1.23.7 Requires-Python >=3.8; 1.23.8 Requires-Python >=3.8; 1.23.9 Requires-Python >=3.
8; 1.23.9rc1 Requires-Python >=3.8; 1.23.9rc2 Requires-Python >=3.8; 1.24.0 Requires-Python >=3.8; 1
.24.1 Requires-Python >=3.8; 1.24.10 Requires-Python >=3.8; 1.24.11 Requires-Python >=3.8; 1.24.12 R
equires-Python >=3.9; 1.24.13 Requires-Python >=3.9; 1.24.2 Requires-Python >=3.8; 1.24.3 Requires-P
ython >=3.8; 1.24.4 Requires-Python >=3.8; 1.24.5 Requires-Python >=3.8; 1.24.6 Requires-Python >=3.
8; 1.24.7 Requires-Python >=3.8; 1.24.8 Requires-Python >=3.8; 1.24.9 Requires-Python >=3.8; 8.3.0 R
equires-Python >=3.8; 8.4.0 Requires-Python >=3.8; 8.4.1 Requires-Python >=3.8; 8.4.2 Requires-Pytho
n >=3.8; 8.5.0 Requires-Python >=3.8; 9.0.0 Requires-Python >=3.8
ERROR: Could not find a version that satisfies the requirement doclayout-yolo (from pdf2zh) (from ve
rsions: none)
ERROR: No matching distribution found for doclayout-yolo

后面去包管理中心(https://pypi.org/project/pdf2zh/1.6.9/)看了下,这里确实有说明需要3.8以上。(因为没研究过,不知道pypi这里的说明是不是分开维护的,和github仓库这边的有些差异……)

之后换了,3.11,安装正常

2.pdf2zh命令报错OpenCV bindings requires "numpy" package:

提示没有numpy,但是实际上是有的,不确定是本地环境问题,还是依赖包直接有冲突?

$ pdf2zh  confpgxc_final.pdf
OpenCV bindings requires "numpy" package.
Install it via command:
    pip install numpy
Traceback (most recent call last):
  File "F:\Python\Python311\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python311\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
    ^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python311\Scripts\pdf2zh.exe\__main__.py", line 4, in <module>
  File "F:\Python\Python311\lib\site-packages\pdf2zh\pdf2zh.py", line 12, in <module>
    import doclayout_yolo
    ^^^^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python311\lib\site-packages\doclayout_yolo\__init__.py", line 5, in <module>
    from doclayout_yolo.data.explorer.explorer import Explorer
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python311\lib\site-packages\doclayout_yolo\data\__init__.py", line 3, in <module>
    from .base import BaseDataset
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python311\lib\site-packages\doclayout_yolo\data\base.py", line 12, in <module>
    import cv2
    ^^^^^^^^^^
  File "F:\Python\Python311\lib\site-packages\cv2\__init__.py", line 11, in <module>
    import numpy
    ^^^^^^^^^^^^
  File "F:\Python\Python311\lib\site-packages\numpy\__init__.py", line 194, in <module>
    from . import lib
    ^^^^^^^^^^^^^^^^^
  File "F:\Python\Python311\lib\site-packages\numpy\lib\__init__.py", line 23, in <module>
    from . import _index_tricks_impl
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python311\lib\site-packages\numpy\lib\_index_tricks_impl.py", line 12, in <module>

    import numpy.matrixlib as matrixlib
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python311\lib\site-packages\numpy\matrixlib\__init__.py", line 4, in <module>
    from . import defmatrix
    ^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python311\lib\site-packages\numpy\matrixlib\defmatrix.py", line 12, in <module>
    from numpy.linalg import matrix_power
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python311\lib\site-packages\numpy\linalg\__init__.py", line 88, in <module>
    from . import _linalg
    ^^^^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python311\lib\site-packages\numpy\linalg\_linalg.py", line 41, in <module>
    from numpy._typing import NDArray
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python311\lib\site-packages\numpy\_typing\__init__.py", line 185, in <module>
    from ._array_like import (
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python311\lib\site-packages\numpy\_typing\_array_like.py", line 162, in <module>
    from typing import Never as _UnknownType
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: cannot import name 'Never' from 'typing' (F:\Python\Python311\lib\typing.py)

$ pip install numpy
Requirement already satisfied: numpy in f:\python\python311\lib\site-packages (2.1.3)
Byaidu commented 1 week ago

好的,这就修改一下

Byaidu commented 1 week ago

numpy 应该是版本低了,可以重装一下

yansheng836 commented 1 week ago

好像不是这个numpy版本低的问题,它当前已经是最新了

$ pip uninstall numpy
Found existing installation: numpy 2.1.3
Uninstalling numpy-2.1.3:
  Would remove:
    f:\python\python311\lib\site-packages\numpy-2.1.3-cp311-cp311-win_amd64.whl
    f:\python\python311\lib\site-packages\numpy-2.1.3.dist-info\*
    f:\python\python311\lib\site-packages\numpy.libs\libscipy_openblas64_-c16e4918366c6bc1f1cd71e28c
a36fc0.dll
    f:\python\python311\lib\site-packages\numpy.libs\msvcp140-d64049c6e3865410a7dda6a7e9f0c575.dll
    f:\python\python311\lib\site-packages\numpy\*
    f:\python\python311\scripts\f2py.exe
    f:\python\python311\scripts\numpy-config.exe
Proceed (Y/n)? y
  Successfully uninstalled numpy-2.1.3

$ pip install numpy
Collecting numpy
  Using cached numpy-2.1.3-cp311-cp311-win_amd64.whl (12.9 MB)
Installing collected packages: numpy
Successfully installed numpy-2.1.3

或者看这个:https://pypi.org/project/numpy/#history

Byaidu commented 1 week ago

不知道了,可能你安装的 python 有问题吧,正常 numpy 引入 typing 不应该报错的

yansheng836 commented 1 week ago

卸载干净,又重新安装了个3.12,用上了,感谢。

其实还有个问题,一开始报错,看了这个(https://github.com/Byaidu/PDFMathTranslate/issues/27)之后发现默认是用Google翻译的,fq之后就好了,有点好奇的是为啥这里提示连接问题,里面有个url,却不是google翻译那个呢?

$ pdf2zh confpgxc_final.pdf
Downloading...
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "F:\Python\Python312\Scripts\pdf2zh.exe\__main__.py", line 7, in <module>
  File "F:\Python\Python312\Lib\site-packages\pdf2zh\pdf2zh.py", line 229, in main
    extract_text(**vars(parsed_args))
  File "F:\Python\Python312\Lib\site-packages\pdf2zh\pdf2zh.py", line 73, in extract_text
    urllib.request.urlretrieve("http://huggingface.co/juliozhao/DocLayout-YOLO-DocStructBench/resolv
e/main/doclayout_yolo_docstructbench_imgsz1024.pt",pth)
  File "F:\Python\Python312\Lib\urllib\request.py", line 240, in urlretrieve
    with contextlib.closing(urlopen(url, data)) as fp:
                            ^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python312\Lib\urllib\request.py", line 215, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python312\Lib\urllib\request.py", line 521, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python312\Lib\urllib\request.py", line 630, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python312\Lib\urllib\request.py", line 559, in error
    return self._call_chain(*args)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Python\Python312\Lib\urllib\request.py", line 492, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "F:\Python\Python312\Lib\urllib\request.py", line 639, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 503: Service Unavailable
Byaidu commented 1 week ago

这个链接是布局分析模型