How to install Python Imaging (PIL) in a virtualenv with –no-site-packages
This gets PIL working with JPEG/ZLIB support within a virtualenv (with –no-site-packages). This has specifically been tested with Python 2.7 on Ubuntu 11.04.
1. Install the dependencies needed for the PIL library, using aptitude. This installs everything but PIL itself.
sudo apt-get build-dep python-imaging
2. Install the python-dev package so that we can compile PIL.
sudo apt-get install python-dev
3. Make sure that PIL's setup.py can find JPEG/ZLIB, by supplying a settings override file. Ubuntu installs these libs in a non-standard place, so we need to let the package's installer know where to find them. Create a file named setup_site.py in the root of your virtualenv (or somewhere in your path) with the following contents:
JPEG_ROOT = ('/usr/lib/i386-linux-gnu/', '/usr/lib/x86_64-linux-gnu/')
ZLIB_ROOT = ('/usr/lib/i386-linux-gnu/', '/usr/lib/x86_64-linux-gnu/')
FREETYPE_ROOT = ('/usr/lib/i386-linux-gnu/', '/usr/lib/x86_64-linux-gnu/')
4. From the root of your virtualenv (with it activated) run:
pip install PIL
That's it! If you run into any problems on Ubuntu 11.04+, leave a comment and I'll try to update the post accordingly.
-
Ben Davis
-
kourosh shafi