PIL IOError: decoder jpeg not available

Mon 04 April 2011 by Lance Jian in Python.

Today I got this error when I try to resize a JPEG image in python using the Python Imaging Library (PIL):

File "/usr/local/lib/python2.6/dist-packages/PIL/Image.py", line 1290, in resize
   self.load()
File "/usr/local/lib/python2.6/dist-packages/PIL/ImageFile.py", line 189, in load
   d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
File "/usr/local/lib/python2.6/dist-packages/PIL/Image.py", line 385, in _getdecoder
   raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available

This is because at the time PIL was being compiled, it did not find the JPEG library. To fix this problem, run:

sudo aptitude install libjpeg-dev

Then you need to uninstall and reinstall the PIL package:

sudo rm -rf /usr/local/lib/python2.6/dist-packages/PIL
sudo easy_install pil

Or if you are using pip:

sudo pip install -I pil

In the output messages, you can find the PIL setup summary like following:

--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
...
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
...
--------------------------------------------------------------------

This shows that now PIL has JPEG support. All the commands here works under Ubuntu 10.04.