PyMuPDF should be installed using pip with:
python -m pip install --upgrade pip python -m pip install --upgrade pymupdf
This will install from a Python wheel if one is available for your platform.
If a suitable Python wheel is not available, pip will automatically build from source using a Python sdist. This requires that SWIG is installed:
On Unix-style systems such as Linux, OpenBSD and FreeBSD, use the system package manager to install SWIG.
For example on Debian Linux, do:
sudo apt install swig
On Windows, install SWIG by following the instructions at: https://swig.org/Doc4.0/Windows.html#Windows_installation.
On MacOS, install MacPorts using the instructions at: https://www.macports.org/install.php
Then install SWIG with:
sudo port install swig
PyMuPDF-1.20.0, the required MuPDF source code is already in the
sdist and is automatically built into PyMuPDF.
Wheels are available for Windows (32-bit Intel, 64-bit Intel), Linux (64-bit Intel, 64-bit ARM) and Mac OSX (64-bit Intel), Python versions 3.7 and up.
PyMuPDF does not support Python versions prior to 3.7. Older wheels can be found in this repository and on PyPI. Please note that we generally follow the official Python release schedules. For Python versions dropping out of official support this means, that generation of wheels will also be ceased for them.
There are no mandatory external dependencies. However, some optional feature are available only if additional components are installed:
pymupdf-fonts is a collection of nice fonts to be used for text output methods.
Tesseract-OCR for optical character recognition in images and document pages. Tesseract is separate software, not a Python package. To enable OCR functions in PyMuPDF, the software must be installed and the system environment variable
"TESSDATA_PREFIX"must be defined and contain the
tessdatafolder name of the Tesseract installation location. See below.
You can install these additional components at any time – before or after installing PyMuPDF. PyMuPDF will detect their presence during import or when the respective functions are being used.
Install from source without using an sdist
First get a PyMuPDF source tree:
Clone the git repository at https://github.com/pymupdf/PyMuPDF, for example:
git clone https://github.com/pymupdf/PyMuPDF.git
Or download a
.tar.gzsource release from https://github.com/pymupdf/PyMuPDF/releases.
Install SWIG as described above, then build PyMuPDF:
cd PyMuPDF && python setup.py install
This will automatically download a specific hard-coded MuPDF source release, and build it into PyMuPDF.
One can build with a different MuPDF (for example one installed on the system, or a local custom build) by setting environmental variables.
See the documentation at the start of
setup.pyfor more information.
Enabling Integrated OCR Support
If you do not intend to use this feature, skip this step. Otherwise, it is required for both installation paths: from wheels and from sources.
PyMuPDF will already contain all the logic to support OCR functions. But it additionally does need Tesseract’s language support data, so installation of Tesseract-OCR is still required.
The language support folder location must currently 1 be communicated via storing it in the environment variable
So for a working OCR functionality, make sure to complete this checklist:
- Locate Tesseract’s language support folder. Typically you will find it here:
- Set the environment variable
set TESSDATA_PREFIX=C:\Program Files\Tesseract-OCR\tessdata
- Set the environment variable
This must happen outside Python – before starting your script. Just manipulating
os.environ will not work!
In the next MuPDF version, it will be possible to pass this value as a parameter – directly in the OCR invocations.