当我使用pip安装paddleocr时,如何修复“PyMuPDF错误”?

6

在执行pip install paddleocr时,我遇到了一个构建PyMuPDF wheel的错误。

Building wheels for collected packages: PyMuPDF
Building wheel for PyMuPDF (setup.py) ... error
error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [70 lines of output]



Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\3551\AppData\Local\Temp\pip-install-ip72hta1\pymupdf_f7a2c6bc313a492fa6c66ad0817a4616\setup.py", line 487, in <module>
          mupdf_local = get_mupdf()
                        ^^^^^^^^^^^
        File "C:\Users\3551\AppData\Local\Temp\pip-install-ip72hta1\pymupdf_f7a2c6bc313a492fa6c66ad0817a4616\setup.py", line 450, in get_mupdf
          return tar_extract( mupdf_tgz, exists='return')
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\3551\AppData\Local\Temp\pip-install-ip72hta1\pymupdf_f7a2c6bc313a492fa6c66ad0817a4616\setup.py", line 183, in tar_extract
          t.extractall()
        File "C:\Users\3551\AppData\Local\Programs\Python\Python311\Lib\tarfile.py", line 2059, in extractall
          self.extract(tarinfo, path, set_attrs=not tarinfo.isdir(),
        File "C:\Users\3551\AppData\Local\Programs\Python\Python311\Lib\tarfile.py", line 2100, in extract
          self._extract_member(tarinfo, os.path.join(path, tarinfo.name),
        File "C:\Users\3551\AppData\Local\Programs\Python\Python311\Lib\tarfile.py", line 2173, in _extract_member
          self.makefile(tarinfo, targetpath)
        File "C:\Users\3551\AppData\Local\Programs\Python\Python311\Lib\tarfile.py", line 2214, in makefile
          with bltn_open(targetpath, "wb") as target:
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
      FileNotFoundError: [Errno 2] No such file or directory: '.\\mupdf-1.20.3-source\\thirdparty\\harfbuzz\\test\\shaping\\texts\\in-house\\shaper-indic\\script-devanagari\\utrrs\\codepoint\\IndicFontFeatureCodepoint-AdditionalConsonants.txt'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for PyMuPDF
  Running setup.py clean for PyMuPDF
Failed to build PyMuPDF
ERROR: Could not build wheels for PyMuPDF, which is required to install pyproject.toml-based projects

我尝试使用 pip install wheel 命令安装 PyMuPDF,然后使用 pip install PyMuPDF 安装 paddleocr,但是出现了相同的问题,即在构建 PyMuPDF 的 wheel 文件时出错。

我的电脑是 intel i3, 64 位处理器,Python 版本为 3.11.3


1
请不要发布文字图片。将完整的错误信息复制/粘贴到您的问题中,使用[编辑]功能。然后通过高亮并点击“{}`”按钮将其放入代码格式中。这样,它们会更易读和可访问。您只会增加实际阅读您问题的人数。 - FlyingTeller
还请提供有关您的操作系统和Python设置的信息。 - FlyingTeller
感谢您的建议,我已根据它更新了我的问题。 - Jinen Rathore
你是否坚持使用Python 3.11,还是愿意切换到更低的版本? - FlyingTeller
1
paddleocr的要求是PyMuPDF<1.21.0PyMuPDF==1.20.2(符合paddleocr要求的最新版本)。而PyMuPDF==1.20.2只有适用于Python 3.10的whl文件。 - undefined
显示剩余14条评论
3个回答

6
试试这个 pip install "paddleocr>=2.0.1" --upgrade PyMuPDF==1.21.1 对我来说有效。

4

paddleocr 需要 PyMuPDF<1.21.0PyMuPDF==1.20.2(符合 paddleocr 要求的最新版本)仅有适用于 Python 3.10 的 whl 文件。因此,pip 会回退尝试从源码进行安装。

精确的错误信息来自 PyMuPDF 安装脚本尝试下载其中一个依赖项,在 .tar.gz 文件解压过程中失败。现在你有不同的选项:

  1. 手动下载https://mupdf.com/downloads/archive/mupdf-1.20.3-source.tar.gz,然后将存档文件提取到您选择的路径。将环境变量PYMUPDF_SETUP_MUPDF_BUILD设置为提取的mupdf-1.20.3文件夹的路径,然后尝试运行pip install PyMuPDF==1.20.2。请注意,此方法还需要一个可用的编译器。

  2. 下载此非官方的whl文件:https://drive.google.com/drive/folders/1PESjDkovpvnrWFTKji4-qgT3rcVz-o-F?usp=sharing,并使用pip install <path to the whl file>进行安装。


1

对于在 macOS 上遇到此问题的开发者,您需要安装 pip install PyMuPDF==1.20.0 因为 PaddleOCR 需要 PyMuPDF<1.21.0

如果您仍然遇到 ERROR: Failed building wheel for PyMuPDF 问题,请先尝试 brew install swig,然后再尝试 pip install PyMuPDF==1.20.0,这样就可以解决问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接