99

How to install PIL on Ubuntu with JPEG support

I was trying to get PIL to work on my ubuntu box but it failed to handle JPEGs. The system responded with the dreaded "IOError: decoder jpeg not available". Here is what I did to solve it...

I am running my pylons project through a virtual environment. All the libraries are installed with pip, always run from within the virtual environment. When I tried to use PIL on my MAC I had no problems, but the same code just failed on Ubuntu (I was trying to generate some thumbnails from JPEGs).

The reason was that PIP was not installed properly. It required for the installation some libraries for dealing with JPEGs which it failed to find. What you have to do is tell it where to get it from. Before doing that make sure that your system has the necessary libraries. This seems to be enough for most cases:

sudo apt-get install libjpeg62-dev

If this does not do it, then try all the other possible libjpeg libraries. Now follow the steps:

Step 1: Download the code of PIL with pip (or rather uninstall PIP first - pip uninstall PIL)

/myEnv/bin/pip install --no-install PIL

This should download the source in the build directory of your environment.

cd /myEnv/build/PIL

Step 2: Edit the setup.py file

Find this line:

JPEG_ROOT = None

and change it to:

JPEG_ROOT = libinclude("/usr/lib")

Have a look at the setup.py in case you need to specify separately the lib and the include directory.

Step 3: Finish the installation

/myEnv/bin/pip install PIL

If all went well then you should see at the end of the installation something like this (see the JPEG line):

 -------------------------------------------------------------------
    *** TKINTER support not available
    --- JPEG support available
    --- ZLIB (PNG/ZIP) support available
    --- FREETYPE2 support available
    *** LITTLECMS support not available
--------------------------------------------------------------------


comments powered by Disqus