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:

  1. Install libraries via APT:

    $ sudo apt-get install libjpeg-dev libpng-dev zlib1g-dev liblcms1-dev python-dev
  2. download the jpeg decoder here. Install it:

    $ cd jpeg-8c
    $ ./configure --enable-shared
    $ make
    $ sudo make install
  3. 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”
  4. Install

    1
    2
    3
    
    $ python setup.py build_ext -i
    $ python selftest.py
    $ sudo python setup.py install
  5. 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! ;)

Related Posts:

  • http://twitter.com/whatupderek Derek Reynolds

    I can’t seem to build PIL with zlib support. Followed these instructions, but always end up with this output:

    *** TKINTER support not available
    — JPEG support available
    *** ZLIB (PNG/ZIP) support not available
    *** FREETYPE2 support not available
    — LITTLECMS support available

  • http://darkcoding.net Graham King

    @Derek

    On Ubuntu you need to add a soft link to libz.so:
    On 32bit: sudo ln -s /usr/lib/i386-linux-gnu/libz.so /usr/lib
    On 64bit: sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib

    See here: http://www.foxhop.net/ubuntu-python-easy_install-pil-does-not-install-zlib-support

  • diegueus9

    I got two errors:

    First:
    when i’m installing jpeg-8c, i can’t make ‘make install’ but i did ‘sudo make install’ i don’t know if maybe this is a typo

    Two:
    In final step:
    >>> import _imagin
    Traceback (most recent call last):
    File “”, line 1, in
    ImportError: libjpeg.so.8: cannot open shared object file: No such file or directory

    So, I wonder if that works with:
    mkvirtualenv –no-site-packages ?

Share