[Image-SIG] Building PIL for Windows (Python 2.4)

Paul Moore p.f.moore at gmail.com
Thu Dec 9 12:31:00 CET 2004


I have successfully built PIL 1.1.5b1 for Python 2.4, using the free
Mingw implementation of gcc. Here are instructions, for anyone who is
interested. (Please note, there is one place I needed to modify the
PIL sources - I'm not sure if what I did was the best way, but maybe
Fredrik could review and apply something suitable in the core
sources...)

I have mingw 3.3.3 installed - you need a recent enough version to
support building binaries which link to msvcr71. You need to have
followed the instructions in the Python documentation ("Installing
Python Modules" section 6.2.2) on building libpython24.a.

You also need the libraries freetype, tiff, jpeg, zlib and libgw32c
from the GnuWin32 project (gnuwin32.sourceforge.net). Get the
"developer files" distributions, and unzip them into a suitable
location (I used "..\Libs" relative to my PIL build directory - the
instructions below will be based on this).

>From ..\Libs\lib, delete all of the .lib and .dll.a files - these link
to DLL versions of the libraries, and can get picked up by accident.
We want to link statically, to reduce dependencies.

I also have ActiveTCL (aspn.activestate.com) installed, for the TCL/TK
header files and link libraries. You need to copy tcl84.lib to
libtcl84.a, and tk84.lib to libtk84.a, to match mingw naming
conventions.

OK, that's the environment set up.

Now, we need to fix a problem in the PIL sources. Edit ImPlatform.h,
and comment out the definition of INT64. (This definition clashes with
others in some of the Windows header files, and I found that removing
it was the quickest fix to get everything to build...)

Now, in setup.py, set the roots:

FREETYPE_ROOT = libinclude("../Libs")
JPEG_ROOT = libinclude("../Libs")
TIFF_ROOT = libinclude("../Libs")
ZLIB_ROOT = libinclude("../Libs")
TCL_ROOT = libinclude("C:/Apps/Tcl") # Or wherever you installed ActiveTCL

Finally, you need to add a couple of dependencies to the _imagingft
extension (again, in setup.py):

   exts.append(Extension(
            "_imagingft", ["_imagingft.c"], libraries=["freetype",
"z", "gw32c"],
            define_macros=defs
         ))

[The formatting is probably messed up here - it's the addition of "z"
and "gw32c" in the libraries argument that matters]

Now, you should just be able to build.

python setup.py build --compiler=mingw32 bdist_wininst

Paul.

PS I have a binary installer built. While I don't want to end up mass
mailing it to everyone, if anyone can offer space to host it, I'd be
happy to make it available. No guarantees beyond "it works for me",
unfortunately :-)


More information about the Image-SIG mailing list