Skip to content
JorjMcKie edited this page May 18, 2015 · 22 revisions

I feel that the original comments on how to install the product are very, shall we say: economic.
The MuPDF documentation is by no means more explicit.
At least I had to guess my way through the installation process. Therefore here is my experience with installing python-fitz on a Windows 7.

Step 1: Download python-fitz
Download this repository and unzip it. This will give you a folder, which I called "PyFitz".

Step 2: Download MuPDF 1.2
Download mupdf version 1.2 source (important - the Python binding will probably not work with other versions and definitely not with the current 1.7!), and unzip it. I called the resulting folder "mupdf12", which I put inside PyFitz.

Step 3: Generate MuPDF
Here it becomes interesting:
With Visual Studio under Windows, everything is fairly simple, once you have understood what you must do.

3.1 Enter Visual Studio
Enter VS and open the solution in mupdf12/win32: "mupdf.sln".
If your VS version is newer than the existing format, VS will now automatically translate all projects (.vcproj) into .vcxproj versions.

3.2 Build the VS mupdf solution
Change the "active solution configuration" to Release (BUILD.Configuration Manager ...).
Important: If your Python depends on another C++ compiler than the one of your Visual Studio version, you now have to adjust each project in the solution to reflect the correct compiler / linker and include directories.
I used a VS property sheet to do this.
Now invoke BUILD.
This process will generate all sorts of stuff. Among it are the 3 little utilities "mupdf.exe", "mutool.exe" and "mudraw.exe", which are contained in the mupdf non-source download package.

3.3 Build / setup python-fitz
The VS build process in the previous section 3.2 also generates the following three objects:
libmupdf.lib, libmupdf-nov8.lib, libthirdparty.lib
They are all you need for your Python build / setup! Therefore, you need a different setup.py than the original one in PyFitz like so:

from distutils.core import setup, Extension  
module = Extension('fitz._fitz',
               include_dirs=['./fitz', './mupdf12/fitz'],  # I have put mupdf12 under my PyFitz directory
               libraries=['libmupdf-nov8',                 # copy these into PyFitz or specify a dir
                          'libmupdf',                      # where to find them.
                          'libthirdparty'],
               extra_link_args=['/NODEFAULTLIB:LIBCMT'],   # important for a successful link step
               sources=['./fitz/fitz_wrap.c'])
setup(name = 'fitz',
      version = '0.0.9',
      description = 'Python bindings for MuPDF rendering library',
      classifiers = [ ... ],
      url = 'https://github.com/rk700/python-fitz',
      author = 'Ruikai Liu',
      author_email = '[email protected]',
      license = 'GPLv3+',
      packages = ['fitz'],
      ext_modules = [module])

4. Conclusion
In a Windows VS configuration you can forget all about the hassle with these 3rd party products - the corresponding thirdparty.lib is automatically generated.
My configuration:
Win 7 SP1, Python(x,y) 2.7.9, Visual Studio Community 2013, (different!) VC++ version for Python: "Visual C++ for Python".

5. Final Remark (unrelated): vcvarsall.bat
I am one of those who have problems with this "unable to locate vcvarsall.bat" message during python setups.
The follwong cmd file is a solution:

cd "C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python"
call vcvarsall.bat x86
SET DISTUTILS_USE_SDK=1
SET MSSdk=1
cd <to where your setup.py is sitting>
python setup.py install
Clone this wiki locally