2

I am having this issue of importing the fitz library in PyCharm. I pip installed PyMuPDF and in my code I added "import fitz" but it is giving me this error:

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'))

How do I fix this error?

jjboi8708
  • 65
  • 1
  • 7

2 Answers2

0

It seems you're using M1-macbook, hence this error (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')). Directly doing pip install PyMuPDF builds for 'x86_64' architecture. You need to build the PyMuPDF directly from the source release by the following:

  • First install mupdf, swig and freetype
brew install mupdf swig freetype
  • then install from the source:
pip install https://github.com/pymupdf/PyMuPDF/archive/master.tar.gz

You can learn more from here:

Musabbir Arrafi
  • 744
  • 4
  • 18
0

The problem with this not working on my mac mini m2 chip was because there wasn't any wheel that supported it but there is a new wheel. Just use this in your terminal if you're having the same problem.

pip install --upgrade pymupdf
jjboi8708
  • 65
  • 1
  • 7