How To Fix The "decoder jpeg not available" Error When Using PIL In Python

In my experience, PIL can be finicky if you don't have everything just right. I recently encountered the following error while working on QuoteRobot.

IOError: decoder jpeg not available

Basically this means that the libjpeg library isn't installed. This is easy to fix on Linux and Mac OSX (I'm using Mountain Lion).

On Mac, you can use Homebrew to install the libraries. Open terminal and run:

brew update
brew install libjpeg libpng

On Ubuntu, you can use the APT package manager. Open terminal and run:

 sudo apt-get install libjpeg-dev

Once you've installed the libraries, you'll need to re-install PIL. Run the following:

pip install -I PIL

Note that if you're installing PIL system wide, you'll need to prepend sudo to that command. However, I'd recommend using Virtualenv instead.

Hopefully this will save you some time.

comments powered by Disqus