我在 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'))
如何修复此错误?
看来您使用的是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
您可以从这里了解更多: