Django, PIL, and libjpeg on Ubuntu 11.10

Posted 13 years ago in General, Code, Server Administration

If you are deploying a django python site using Ubuntu and the virtualenvwrapper to isolate your site's packages you may run into an issue where PIL, the Python Imaging Library just will not upload ImageFields in your models. Luckily I found a quick fix.

First remove any instance of PIL. It will not work if it's already installed just issue: pip uninstall PIL

Second install the necessary dependencies such as libjpeg, libpng, zlib, and libfreetype. Which may be found here: http://packages.ubuntu.com/oneiric/libs/

apt-get install libjpeg8 libpng12-0 libfreetype6 zlib1g

That should install all the necessary dependencies on your system.

Now we create soft-links to the library files PIL expects to find. Of all the solutions I've looked for and attempted this one both works and has minor consequences which would be that they would need to be recreated if Ubuntu changes where those libraries get installed to.


ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib
ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib
ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib

Those commands will create links to those files that reside in the common library location /usr/lib which is where PIL expects to load those modules.

Install PIL

`pip install -U PIL`

Credit really goes to JJ who wrote the tutorial I found at: http://jj.isgeek.net/2011/09/install-pil-with-jpeg-support-on-ubuntu-oneiric-64bits/ however I felt it lacked the basics for beginners like me :P