If you’re getting the following error when uploading on Django:

Upload a valid image. The file you uploaded was either not an image or a corrupted image.

Here’s the Ubuntu version of the post below.  I’m not sure if these steps are all required, but you know that stuff about letting sleeping dogs lie.  It works.

1/  Do we have all necessary libraries? (jpeg, png, etc)

$ sudo aptitude install libjpeg62 libjpeg62-dev
$ sudo aptitude install zlib1g-dev
$ sudo aptitude install libfreetype6 libfreetype6-dev

2/  Are they sym-linked to the folder where PIL is going to look for them?

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

substitute “i386” with “x86_64” if you’re on the 64 platform  (I know, not very elegant, and may break on future upgrades, but it’s all I could find)

3/ Back to our virtualenv

If you had already installed PIL in your environment,

$ source MyEnv/bin/activate
(MyEnv)$ pip uninstall PIL
(MyEnv)$ pip install PIL

To test it try,

$ python
>>> from PIL import Image
>>> i = Image.open('/home/username/someJpeg.jpg')
>>> i.save('/home/username/someOtherJpeg.jpg')