Byaidu / PDFMathTranslate

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

ImportError: DLL load failed while importing _rust: #90

Open Andy-AO opened 1 day ago

Andy-AO commented 1 day ago

问题描述

执行 pdf2zh document.pdf 出现 ImportError: DLL load failed while importing _rust: The specified procedure could not be found.

python --version Python 3.9.0

image

测试文档

document.pdf

Byaidu commented 23 hours ago

建议重装一下

reycn commented 9 hours ago

楼上的解决方案应该可以帮助解决该问题,暂时关闭 issue。

Andy-AO commented 7 hours ago

楼上的解决方案应该可以帮助解决该问题,暂时关闭 issue。

重装之后,该问题重现

(pdf2zh_ri) D:\software\green\pdf2zh_ri> pdf2zh document.pdf
Traceback (most recent call last):
  File "C:\Users\Andy\.pyenv\pyenv-win\versions\3.9.0\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\Andy\.pyenv\pyenv-win\versions\3.9.0\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\software\green\pdf2zh_ri\Scripts\pdf2zh.exe\__main__.py", line 7, in <module>
    sys.exit(main())
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdf2zh.py", line 262, in main
    extract_text(**vars(parsed_args))
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdf2zh.py", line 72, in extract_text
    import pdf2zh.high_level
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\high_level.py", line 12, in <module>
    from pdf2zh.converter import (
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\converter.py", line 35, in <module>
    from pdf2zh.image import ImageWriter
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\image.py", line 14, in <module>
    from pdf2zh.layout import LTImage
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\layout.py", line 21, in <module>
    from pdf2zh.pdfinterp import Color, PDFGraphicState
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdfinterp.py", line 11, in <module>
    from pdf2zh.pdfdevice import PDFDevice, PDFTextSeq
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdfdevice.py", line 15, in <module>
    from pdf2zh.pdfpage import PDFPage
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdfpage.py", line 6, in <module>
    from pdf2zh.pdfdocument import (
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdfdocument.py", line 23, in <module>
    from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
  File "d:\software\green\pdf2zh_ri\lib\site-packages\cryptography\hazmat\primitives\ciphers\__init__.py", line 11, in <module>
    from cryptography.hazmat.primitives.ciphers.base import (
  File "d:\software\green\pdf2zh_ri\lib\site-packages\cryptography\hazmat\primitives\ciphers\base.py", line 10, in <module>
    from cryptography.hazmat.bindings._rust import openssl as rust_openssl
ImportError: DLL load failed while importing _rust: The specified procedure could not be found.
(pdf2zh_ri) D:\software\green\pdf2zh_ri>
reycn commented 7 hours ago

楼上的解决方案应该可以帮助解决该问题,暂时关闭 issue。

重装之后,该问题重现

(pdf2zh_ri) D:\software\green\pdf2zh_ri> pdf2zh document.pdf
Traceback (most recent call last):
  File "C:\Users\Andy\.pyenv\pyenv-win\versions\3.9.0\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\Andy\.pyenv\pyenv-win\versions\3.9.0\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\software\green\pdf2zh_ri\Scripts\pdf2zh.exe\__main__.py", line 7, in <module>
    sys.exit(main())
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdf2zh.py", line 262, in main
    extract_text(**vars(parsed_args))
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdf2zh.py", line 72, in extract_text
    import pdf2zh.high_level
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\high_level.py", line 12, in <module>
    from pdf2zh.converter import (
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\converter.py", line 35, in <module>
    from pdf2zh.image import ImageWriter
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\image.py", line 14, in <module>
    from pdf2zh.layout import LTImage
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\layout.py", line 21, in <module>
    from pdf2zh.pdfinterp import Color, PDFGraphicState
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdfinterp.py", line 11, in <module>
    from pdf2zh.pdfdevice import PDFDevice, PDFTextSeq
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdfdevice.py", line 15, in <module>
    from pdf2zh.pdfpage import PDFPage
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdfpage.py", line 6, in <module>
    from pdf2zh.pdfdocument import (
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdfdocument.py", line 23, in <module>
    from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
  File "d:\software\green\pdf2zh_ri\lib\site-packages\cryptography\hazmat\primitives\ciphers\__init__.py", line 11, in <module>
    from cryptography.hazmat.primitives.ciphers.base import (
  File "d:\software\green\pdf2zh_ri\lib\site-packages\cryptography\hazmat\primitives\ciphers\base.py", line 10, in <module>
    from cryptography.hazmat.bindings._rust import openssl as rust_openssl
ImportError: DLL load failed while importing _rust: The specified procedure could not be found.
(pdf2zh_ri) D:\software\green\pdf2zh_ri>

您好能不能给一个 conda 环境的 yml? 我试试

Andy-AO commented 7 hours ago

楼上的解决方案应该可以帮助解决该问题,暂时关闭 issue。

重装之后,该问题重现

(pdf2zh_ri) D:\software\green\pdf2zh_ri> pdf2zh document.pdf
Traceback (most recent call last):
  File "C:\Users\Andy\.pyenv\pyenv-win\versions\3.9.0\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\Andy\.pyenv\pyenv-win\versions\3.9.0\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\software\green\pdf2zh_ri\Scripts\pdf2zh.exe\__main__.py", line 7, in <module>
    sys.exit(main())
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdf2zh.py", line 262, in main
    extract_text(**vars(parsed_args))
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdf2zh.py", line 72, in extract_text
    import pdf2zh.high_level
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\high_level.py", line 12, in <module>
    from pdf2zh.converter import (
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\converter.py", line 35, in <module>
    from pdf2zh.image import ImageWriter
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\image.py", line 14, in <module>
    from pdf2zh.layout import LTImage
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\layout.py", line 21, in <module>
    from pdf2zh.pdfinterp import Color, PDFGraphicState
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdfinterp.py", line 11, in <module>
    from pdf2zh.pdfdevice import PDFDevice, PDFTextSeq
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdfdevice.py", line 15, in <module>
    from pdf2zh.pdfpage import PDFPage
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdfpage.py", line 6, in <module>
    from pdf2zh.pdfdocument import (
  File "d:\software\green\pdf2zh_ri\lib\site-packages\pdf2zh\pdfdocument.py", line 23, in <module>
    from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
  File "d:\software\green\pdf2zh_ri\lib\site-packages\cryptography\hazmat\primitives\ciphers\__init__.py", line 11, in <module>
    from cryptography.hazmat.primitives.ciphers.base import (
  File "d:\software\green\pdf2zh_ri\lib\site-packages\cryptography\hazmat\primitives\ciphers\base.py", line 10, in <module>
    from cryptography.hazmat.bindings._rust import openssl as rust_openssl
ImportError: DLL load failed while importing _rust: The specified procedure could not be found.
(pdf2zh_ri) D:\software\green\pdf2zh_ri>

您好能不能给一个 conda 环境的 yml? 我试试

我是这样用的,注意Python版本3.9.0,平台Windows10

python -m venv .
.\Scripts\Activate.ps1
pip install pdf2zh
pdf2zh document.pdf
Andy-AO commented 7 hours ago

刚刚发现用pyenv local 3.11.5更换版本后这个问题消除(还有其他问题,也不能正常用),所以版本3.9.0应该是必要条件。

reycn commented 7 hours ago

似乎是加密包的版本问题,这里提供了解决方案 https://forum.rasa.com/t/from-cryptography-hazmat-bindings-rust-import-importerror-dll-load-failed-while-importing-rust-the-specified-procedure-could-not-be-found/60963/1

等待 windows 机器复现后,看看 setup.py 要不要指定最低的加密包版本。