Skip to content

Windows Binaries Generation

Jorj X. McKie edited this page May 10, 2016 · 9 revisions

This a "How To" install PyMuPDF and MuPDF using Visual Studio.

I am using this procedure to create the binary setup files for PyMuPDF.

Download MuPDF 1.9

As described in the installation chapter of PyMuPDF. Currently (as of May 10th), only version 1.9a can be seen there. But under the archive directory earlier versions are available, too.

I then unzip mupdf-1.9-source.tar.gz (I am using 7zip) until I get a folder named mupdf-1.9-source. Inside this folder, look for directory platform/win32.

Generate MuPDF 1.9

Double click on mupdf.sln in this folder to open it with Visual Studio. The Visual Studio version I am using VS Community 2013 (version 2015 should work too, but you need to use the platform toolset Visual Studio 2013 (v120) in it to compile MuPDF).

VS will automatically upgrade the solution and all 13 project files to version 12.0 (they are on version 8.0).

Now we need to decide whether we generate for x86 or x64 bitness. Let us assume x86. Start Configuration Manager in the BUILD menu and set Active solution configuration to Release and Active solution platform to Win32. Verify that all check boxes in the Build column are checked. Close configuration manager.

Now update the VC++ directories for all projects using their Property Pages. You need a Windows SDK to successfully proceed. For my Windows 10, I am using Windows 10 SDK. For every project, prefix the following 3 directories with the respective SDK directory (using my configuration example - it will be a little different names for Windows 7 and 8):

  • Executable Directories: C:\Program Files (x86)\Windows Kits\10\bin\x86; ...
  • Include Directories: C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\shared; ...
  • Library Directories: C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x86; ...

Now generate the solution. In this process, the project generated will create .exe files and execute them. This may irritate your antivirus program, so you may consider to temporarily deactivate it.

If all worked well you will find the required library files libfonts.lib, libmupdf.lib and libthirdparty.lib (and many more!) in directory ...\platform\win32\Release.

If you use these library files as described so far, your PyMuPDF binary will be a quite large animal of 17+ MB (!). This is because MuPDF now includes support for many, many dozens of fonts from all over the world. If you do not need that or do not like that (I don't), you can reduce their number like so:

  • edit file fitz.h in directory mupdf-1.9-source/include/mupdf

  • insert 2 lines as follows

    #ifndef MUDPF_FITZ_H #define MUDPF_FITZ_H

    #define NOTO_SMALL

    #define TOFU_CJK

  • save and rebuild the solution as described above. Your PyMuPDF binary will now become around 8 MB large.

Generate PyMuPDF

First check that all your include and library directory specs are in order in your setup.py file. Either copy the *.lib files from above into the a directory named in setup.py or change the script.

Second, make sure that your Python version uses the same compiler / linker version as the one used in Visual Studio to create the *.lib files.

Now generate by invoking python setup.py install.

Done.

Fixing common Problems

A common problem is the error error: Unable to find vcvarsall.bat. An easy fix is using the following python++.bat file:

PUSHD "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC"
call vcvarsall.bat x86
SET DISTUTILS_USE_SDK=1
SET MSSdk=1
POPD
python %*

Then do your setup with the command python++ setup.py install

Clone this wiki locally