Installing PyMuPDF on MacOS Big Sur
Asked Answered
P

2

11

I wanted to import fitz in my code. To do that, I tried installing PyMuPDF using

pip3 install PyMuPDF

However, this installation fails and returns this error:

fitz/fitz_wrap.c:2754:10: fatal error: 'fitz.h' file not found
#include <fitz.h>
         ^~~~~~~~
1 error generated.
error: command '/opt/homebrew/clang' failed with exit code 1

I also tried installing mupdf and mupdf-tools via Homebrew. None of them could fix this issue. I would appreciate any help to fix this installation error!

Patrizius answered 28/7, 2021 at 18:2 Comment(0)
R
32

Assuming you are using M1 Mac, you can solve this problem installing mupdf, swig, freetype and latest version of PyMuPDF:

brew install mupdf swig freetype
pip install https://github.com/pymupdf/PyMuPDF/archive/master.tar.gz

Source: https://github.com/pymupdf/PyMuPDF/discussions/875

Rosenblum answered 5/8, 2021 at 13:11 Comment(4)
Wow, this worked like a charm! I tried so many solutions posted online but nothing else worked except this one. Thank you so much!Patrizius
Excellent! After the brew install mupdf swig freetype, doing pip install --upgrade pymupdf also worked well.Meyerbeer
You save my day, works... thanksConiology
I had to install swig-python as well: sudo port install swig-python, only after that the pip install workedIndefectible
H
7

The instructions provided by Juan Garcia worked until June 18th 2022 for me. There's a few workarounds.

Solution #1

Install the wheel package using pip and swig + freetype using homebrew. PyMuPDF should build itself successfully when running pip install pymupdf. This takes about five minutes on a late model M1 MBP. This does not require the mupdf package installed via homebrew.

Solution #2

If you're using homebrew you can downgrade to 1.19.x with the following:

cd "$(brew --repo homebrew/core)" && git checkout 457cb59a52ff7666dc146c1c480d2ea98d63564f;

# If you already have mupdf installed use `brew reinstall` instead of `brew install`
cd "$(brew --repo homebrew/core)" && HOMEBREW_NO_AUTO_UPDATE=1 brew install mupdf;
cd "$(brew --repo homebrew/core)" && git checkout master && brew pin mupdf;

brew install swig freetype;

pip install https://github.com/pymupdf/PyMuPDF/archive/refs/tags/1.19.6.tar.gz;

For reference here is the Formula commit history: https://github.com/Homebrew/homebrew-core/commits/master/Formula/mupdf.rb

Harv answered 23/6, 2022 at 2:1 Comment(1)
Can you please explain more Solution 1, how to do that. I am having err.Gerhardine

© 2022 - 2024 — McMap. All rights reserved.