我在 PyCharm 中使用 fitz 库时遇到导入错误

问题描述 投票:0回答:1

我在 PyCharm 中导入 fitz 库时遇到问题。我 pip 安装了 PyMuPDF 并在我的代码中添加了“import fitz”,但它给了我这个错误:

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/fitz/_fitz.so, 0x0002): tried: '/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/fitz/_fitz.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/fitz/_fitz.so' (no such file), '/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/fitz/_fitz.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

如何修复此错误?

python python-3.x pycharm pymupdf
1个回答
0
投票

看来您使用的是M1-macbook,因此出现此错误

(mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
。直接执行
pip install PyMuPDF
构建“x86_64”架构。您需要通过以下方式直接从源版本构建
PyMuPDF

  • 首先安装
    mupdf
    swig
    freetype
brew install mupdf swig freetype
  • 然后从源安装:
pip install https://github.com/pymupdf/PyMuPDF/archive/master.tar.gz

您可以从这里了解更多:

© www.soinside.com 2019 - 2024. All rights reserved.