Install PIL in Ubuntu with Python 2.7 and Virtualenv
As weird as it may seem, installing PIL in Ubuntu Natty went so smooth compared to my previous installation in Maverick. Did I just miss something?
My setup is Python 2.7, virtualenv with virtualenvwrapper
Anyway, here are the really simple steps:
-
Install libraries via APT:
$ sudo apt-get install libjpeg-dev libpng-dev zlib1g-dev liblcms1-dev python-dev
-
download the jpeg decoder here. Install it:
$ cd jpeg-8c $ ./configure --enable-shared $ make $ sudo make install
-
download PIL. Edit setup.py :
1 2 3
$ tar -xvf Imaging-1.1.7.tar.gz $ cd Imaging-1.1.7 $ nano setup.py
Look for the declaration of JPEG_ROOT and ZLIB_ROOT and replace them as follows:
JPEG_ROOT = “/usr/local/include” ZLIB_ROOT = “/usr/local/include”
-
Install
1 2 3
$ python setup.py build_ext -i $ python selftest.py $ sudo python setup.py install
-
Fire up the python shell and if things went smoothly, the following code will yield no errors:
1 2
$ import PIL $ import _imaging
For further testing, try this:
from PIL import Image im = Image.open("bride.jpg") im.rotate(45).show()
Tell me in the comments if an error occurred when you tried this. Cheers and happy coding!