We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.

"decoder jpeg not available"

This applies to PIL 1.1.4 and earlier. In PIL 1.1.5, the setup.py file has been rewritten. If you’re get this error under 1.1.5 or later, change the setup.py file so that JPEG_ROOT points to the directory where the libjpeg library is installed. See comments in the file for details.

If you’ve already done that, check that your program really is picking up the _imaging module that you’ve built, and not some older version. Try running:

$ python -vv -c "import _imaging"

and check the import log messages carefully.

I cannot seem to get PIL to find my JPEG library

PIL’s build process doesn’t always find the JPEG library, unless everything is installed in the right system-wide directory (a directory where both the build scripts and the compiler/linker is able to find it, that is).

This note contains instructions on how to force PIL to link with a given JPEG library. Note that the approach described here is usually overkill; you can often leave out some of the steps. But to be on the safe side, it’s a good idea to do everything mentioned here:

1. Configure the libImaging core library

When configuring the library, pass in —with-jpeg, pointing to the directory where the libjpeg library is installed. You may also want to do the same thing for the zlib (libz) library.

$ cd libImaging
$ ./configure --with-jpeg=/somelib/lib --with-zlib=/somelib/lib

Check that the configuration script runs to completion; it may fail to find the support libraries, but we’ll fix that shortly.

checking for jpeg_destroy_compress in -ljpeg... no
checking for deflate in -lz... yes

2. Edit the libImaging configuration file

In case the configuration failed to locate either the jpeg library (-ljpeg) or the zlib library (-lz), you have to manually edit the libImaging/ImConfig.h file. Towards the end of that file, make sure the following defines are present:

#define HAVE_LIBZ

Make sure you don’t leave any #undef HAVE_LIBJPEG or #undef HAVE_LIBZ statements in there.

3. Edit the libImaging makefile

To be on the safe side, edit the libImaging/Makefile.in file to point to the jpeg include directory. Change the JPEGINCLUDE definition to:


(where /somelib is the path to your JPEG installation directory)

4. Build the core library

When you’ve changed the configuration and make file, build the core library.

$ cd libImaging
$ make

When the build has finished, make sure that the JpegEncode.o and JpegDecode.o files are present, and that they are not empty. You can compare their size to the Dib.o file, which doesn’t contain any code on non-Windows platforms.

For ZLIB, the corresponding files are ZipEncode.o and ZipDecode.o.

If things don’t look right, remove all object files and rebuild, before proceeding.

On some platforms, the build may fail, complaining about a missing header file:

cc -O -I./. -I/usr/local/include -DHAVE_CONFIG_H -c -o JpegDecode.o 
   In file included from JpegDecode.c:37:
   Jpeg.h:11:21: jpeglib.h: No such file or directory
   make: *** [JpegDecode.o] Error 1

To fix this, install the jpeg developer kit for your platform (usually a libjpeg-devel RPM, or something similar). Or build the JPEG library from source. When you’ve done this, repeat this step.

5. Edit the Python interface build files

Finally, it’s time to build the Python interface library (_imaging). If you’re using the Makefile.pre.in approach, edit the Setup.in file, and make sure that the JPEG and ZLIB lines point to the right directory:


_imaging  _imaging.c decode.c encode.c map.c display.c outline.c path.c \
        -IlibImaging libImaging/libImaging.a \
# *** IJG JPEG library (libjpeg) location
        -I/somelib/include -L/somelib/lib -ljpeg \
# *** ZLIB (libz) location
        -I/somelib/include -L/somelib/lib -lz


If you’re using the setup.py script (Python 2.1 and later), edit the setup.py script and add the JPEG and ZLIB libraries to the INCLUDE_DIRS and LIBRARY_DIRS variables:

INCLUDE_DIRS = ["libImaging"]
LIBRARY_DIRS = ["libImaging"]

# add jpeg directories

# add zlib directories

All that’s left is to (re)build the interface module. Make sure you recompile at least the _imaging, encode, and decode modules (to be on the safe side, remove all object files before building).