I recently upgraded to a CentOS 5.8 VM built by another developer in our shop. Things were working smoothly until I came across an area of our codebase that relied on PIL. (Experienced Pythonistas may start groaning now.) The problem I ran into presented itself with this error:
IOError: decoder jpeg not available
From past experience, I knew that this was probably due to PIL’s being installed via pip
without the right versions of libjpeg
and libjpeg-devel
installed. A quick uninstall/reinstall verified this was the case, since PIL’s installation helpfully tells you what formats are supported after installation.
The solution here is pretty straightforward if you Google around a bit: uninstall PIL again, do a sudo yum install libjpeg
and sudo yum install libjpeg-devel
, and then reinstall PIL. Right? But when I installed the dependencies, yum informed me that the VM was already up-to-date. (Note that this wasn’t a clean VM, and I have no idea whether they’re installed by default. In any case, if you’re running into this problem you should try the yum install
steps just to get them out of the way.)
As it turns out, PIL’s installer only looks for libraries in /usr/lib/
(and a bunch of other places, but this is the relevant bit). But the libjpeg
dependencies were actually installed to /usr/lib64/
. So the trick is to augment PIL’s setup.py
file. Here’s how I did it:
pip uninstall PIL
(if you haven’t already)pip install PIL --no-install
(this will download the source but not install it)vi /path/to/virtualenv/build/PIL/setup.py
(assuming you’re in a virtualenv)- find the line that says ‘
add_directory(library_dirs, "/usr/lib")
‘ - put ‘
add_directory(library_dirs, "/usr/lib64")
‘ just above that line pip install PIL --no-download
Following these steps got me to a working state where PIL reported it had JPEG support.
Props to StackOverflow user ele, whose related question and answer set me on the right path.
Thanks for the tutorial! This helped me with the issue