Skip to Content

Ubuntu PIL JPEG support

Posted on One min read

Got an IOError exception, while trying to process image using PIL, with a next error message:

encoder jpeg not available

PIL is installed within python virtual environment. Figured out, I have no development files for libjpeg installed, so PIL compiles without JPEG support.

The solution is to:

$ sudo apt-get install libjpeg62-dev

Notice: 62 is from libjpeg version 6.2, so it may vary.

Finally, recompile PIL:

$ pip install -U PIL

PIL has JPEG support for now and everything works like a charm.

UPDATE: The method above will not work if you run Ubuntu x86_64.

Since I am now using x86_64 architecture mostly everywhere, I’ve faced an issue where I needed to use an approach with symlinking (mentioned in comments) to achieve PNG/JPEG support in PIL:

$ cd /usr/lib
$ sudo ln -s x86_64-linux-gnu/libjpeg.so
$ sudo ln -s x86_64-linux-gnu/libz.so

I also found it more neat to symlink those libs within the virtualenv’s (which you obviously use, read this if you do not) so we do not need root access and system is more clean eventually:

$ ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /my/env/lib
$ ln -s /usr/lib/x86_64-linux-gnu/libz.so /my/env/lib
comments powered by Disqus