Skip to content

Ubuntu Installation Experience

Aaron V edited this page Jul 8, 2021 · 14 revisions

Updated: 14Nov2018

MuPDF 1.14.0, PyMuPDF 1.14.0

Instructions

This is a list of steps that should lead to a successfully installed PyMuPDF.

  • Get the MuPDF source from the site wget https://mupdf.com/downloads/archive/mupdf-1.14.0-source.tar.gz and decompress it (latest version as of writing. Others available here: https://mupdf.com/downloads/archive/).
  • MuPDF also has a repository on GitHub. This, however, is the latest development version! Do not use it: it is probably not be compatible with the current PyMuPDF.
  • Set environment variables: export CFLAGS="-fPIC" (on CentOS 5, export CFLAGS="-fPIC -std=gnu99" to resolve errors about missing a definition for NAN symbol in the thirdparty/mujs folder). If you do not set the CFLAG -fPIC, you may also run into a linking error when you run setup.py.
  • Run the initial make: sudo make HAVE_X11=no HAVE_GLFW=no HAVE_GLUT=no prefix=/usr/local
  • If no issues occur install: sudo make HAVE_X11=no HAVE_GLFW=no HAVE_GLUT=no prefix=/usr/local install
  • You will most likely run into issues if you do not use sudo, the install command will fail if the make process is unable to create the destination libraries for the mupdf executables.
  • Get the corresponding version of PyMuPDF: git clone -b <correct branch> https://github.com/rk700/PyMuPDF.git (<correct branch> should match mutool version).
  • Edit the setup.py to point to the correct directories as indicated by the prefix used when making.

Here is the resp. code snippet:

...
include_dirs=['/usr/local/include/mupdf',    # we need the path of the MuPDF and zlib$
              '/usr/local/thirdparty/zlib',  # '/usr/include/mupdf',
             ],
library_dirs=['/usr/local/lib'],
libraries=['mupdf',
            #'crypto', #openssl is required by mupdf on archlinux
            #'jbig2dec', 'openjp2', 'jpeg', 'freetype',
           'mupdf-third', # the '-' is new in v1.14.0
          ], # the libraries to link with
...

(Comment unnecessary libraries out)

  • Run python setup.py build

If no exception is thrown install either with python setup.py install or pip install.


Alternative method

The following worked for me on Ubuntu 18.04.3 LTS, after having no luck with the above.

sudo apt install python3-pip
sudo -H pip3 install --upgrade pip
sudo -H python3.6 -m pip install -U pymupdf
Clone this wiki locally