wiredfool

How to build the Python Imaging Library For Windows

A short howto for those who aren’t exactly used to building open source software with Visual Studio 2003. And for good measure, I’ll include the patch to build PIL with support for Group3/4 Tiff image compression. This is more difficult than it should be due to a lack of googlable directions.

First, to do anything interesting with PIL, you will need to assemble some dependencies. Libjpeg is the only one required to pass the self test, but getting zlib nets .png support, which is useful for me. Libtiff is necessary for the Group3/4 patch, but otherwise is not needed.

I’m not including support for freetype or tcl, since I don’t really have a need for them. Freetype should be a similar process to this. Tcl I’m not so sure of.

The dependencies are at gnuwin32.sourceforge.net. Download the source packages for zlib, libjpeg, and libtiff. Don’t use the compiled ones, since they introduce dependencies to the mingw compiler.

Build each of these packages in their source directory by running the nmake command in a Visual Studio command window (it sets up useful environments and stuff). Libtiff builds cleanly with “nmake /f Makefile.vc” Libjpeg requires copying a header file from jconfig.vc to jconfig.h, then running “nmake /f makefile.vc”. Zlib has the make file in a win32 directory, so the command is “nmake /f win32/Makefile.msc”

Once these three libraries are built, copy the entire source directories them to the root of the PIL directory. I named them libtiff, libjpeg, and zlib.

If you’re using libtiff, apply this patch. (edit, patch was broken. Now fixed.) The original patch was for PIL 1.1.4. I updated it so that it works for me on 1.1.5. I don’t vouch for its correctness any farther than it’s working for me.

If you’re not using libtiff, all you need to do to the setup is to edit the setup.py script to point it at the libraries.

JPEG\_ROOT='./libjpeg'
ZLIB\_ROOT='./zlib'

Now we’re ready to build. Following the PIL directions, run: “python setup.py build\_ext -i”.
That should work, and the selftest should run. If you should need to tweak and rebuild, run “python setup.py clean” and “del PIL/\_imaging.pyd”.

When testing, you may want to uninstall any versions of PIL that may be in your site packages, since it will give misleading results when running the selftest.

No comments

No comments yet. Be the first.

Leave a reply

You must be logged in to post a comment.