Newer versions of virtualenv don’t include the system wide site-packages folder (which is a good thing) so if you’re using a virtualenv you’ll have to install your own copy of PIL. The problem is that by default pip install PIL on webfactions servers won’t provide support for jpeg, png, freetype or littlecms. Maybe you can live without freetype and littlecms, but PIL is essentially useless without support for jpg or png. This blog post outlines how to install your own version of PIL with full support for all the things.

Before I get stuck in I want to point out that the this post was a great help to me credit has to go to seanf. What follows in this post is very close to what he suggested. The main difference in this post is that in my web faction .bashrc file I always alias python=python2.7 so in the below commands I’m implicitly using python2.7. In seanf’s solution he’s explicitly stating python2.7.

Check Python Version

Type which python at the command line and you should see the /usr/local/python2.7 as part of the output. If you don’t then you’ll want to alias python=python2.7 in your .bashrc file.

Download PIL

Edit setup.py

PIL won’t install with support for jpeg, zlib, freetype and littlecms because it can’t find the setup.py script can’t find the libraries. We have to give it a little hand, so crack open setup.py in vim (vim setup.py) and go to line 36(ish) and specify the library paths manually –

Don’t do what I did at this stage, which is forget to install the compiled code and then spend half an hour wondering why all ImageFields in django where returning an error complaining about corrupted images. The battle isn’t over yet soldier, keep going …

Install It

If you’re using virtualenv double check that your virtual environment is activated. If it isn’t do that now before proceeding –