Install PIL with Jpeg support on Ubuntu Oneiric 64bit

I am posting this because it took me ages to figure out how to solve this one.

I could not get PIL to compile with JPEG, Zlib or freetype support on my virtualenv. I am using Ubuntu Oneiric Beta1 on a Lenovo Thinkpad X220. That is a 64bit installation.

As read in every blog post out there, you first need to install the system libraries so PIL can find them.

$ sudo apt-get install libjpeg libjpeg-dev libfreetype6 libfreetype6-dev zlib1g-dev

After that, your regular pip install PIL should work under most situations. In my case I was still seeing this summary after the installation:

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

After a lot of googling around, I found this solution on Ubuntu forums.
It turns out that the APT installations put the libraries under /usr/lib/x86_64-linux-gnu and PIL will search for them in /usr/lib/. So you have to create symlinks for PIL to see them.

# ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib
# ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib
# ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib

Now proceed and reinstal PiL, pip install -U PIL:

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

tada :D !

Update:
I just had this issue again on Ubuntu Precise, I found a solution here:
http://www.sandersnewmedia.com/why/2012/04/16/installing-pil-virtualenv-ubuntu-1204-precise-pangolin/

# ln -s /usr/lib/`uname -i`-linux-gnu/libfreetype.so /usr/lib/
# ln -s /usr/lib/`uname -i`-linux-gnu/libjpeg.so /usr/lib/
# ln -s /usr/lib/`uname -i`-linux-gnu/libz.so /usr/lib/

Note the uname -i that prints the box’s arquitecture. This is a much more generic solution!

How to do it on Ubuntu Precise Pagolin 12.04

  • Airtonix

    OCD Eye twitching rage here….

    Needs to be 

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

    • http://jj.isgeek.net Jj

      I used # to indicate root shell. But yes, it would have been more clear to explicitly use sudo

      • darkpixel

        Less easy to copy/paste when you put the ‘#’ in front of it… ;)

        • http://twitter.com/bigcatmm bigcatmm

          ‘#’ is a convention for a root shell, as Jj stated above.  Not everyone uses the ‘sudo’ command for escalated (root) privileges.  The ‘#’ (instead of ‘$’) succinctly communicates that the command should be executed by a privileged user (usually root).

          If you’re copying and pasting ‘sudo’ commands, you probably should think twice before executing said command.

          Thanks for the blog post Jj!

          • darkpixel

            I wasn’t advocating getting rid of ‘#’ and switching to sudo.  Get rid of both.

    • Joshua

      Depends upon your architecture:

      In my case:

      /usr/lib/i386-linux-gnu/

  • http://twitter.com/ceolwulf ceolwulf

    Thanks for the blog post! This was quite annoying.

  • http://www.facebook.com/max.m.rasmussen Max M Rasmussen

    A dirty way to do it, but it worked nicely for me after I changed it to my 32 bit distro:

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

  • Pingback: Instalando suporte JPEG e PNG para o PIL no Ubuntu Oneiric 64bits | Gilson #DEV

  • Pingback: Install python PIL ( Python image Library ) on Ubuntu 11.10 Oneiric | Django Best Practice

  • Leonardo Vidarte

    thanks!

  • Sebpiq

    Thanks !!! Saved me quite some time …

  • Emery Clark

    thanks man, sweet

  • http://twitter.com/cduranti chris duranti

    Thanks so much! Django kept crashing, but only on production. This did the trick, apparently there was no jpeg/png support on ec2 but my computer ships with it. Oops…

  • Alan gormley

    Thanks, you’ve stopped me banging my head off the desk. Same as Chris, aws did not have support.

  • juanpex

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

    also works

    • http://andrewbadr.com/ Andrew Badr

      Thanks! This is what I needed.

  • Pingback: Install PIL on Ubuntu - ??? in ????????

  • Anonymous

    For me only worked when linked to virtualenv lib dir.

    do it:

    $ cd $VIRTUAL_ENV/lib
    $ ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so
    $ ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so
    $ ln -s /usr/lib/x86_64-linux-gnu/libz.so

  • Pingback: How to install PIL with ZIP, JPEG, etc. on Ubuntu 11.10 | PHP Developer Resource

  • Alek314

    APT installations put the libraries under /usr/lib/x86_64-linux-gnu
    GREAT HELP! Thank you amigo!

  • http://twitter.com/mikeywaites mike waites

    :( none of these have worked for me :/

  • Pingback: Installing PIL into a virtualenv properly in Ubuntu « Darren's Blog.

  • Anonymous

    How about using Pillow instead PIL. AFAIK one hasn’t such problem?

  • Mauro Baraldi

    Well, have installed i386 version, and seems to be ok http://pastebin.com/a762sHGy. BUT, when I try to open a jpeg image with ImageTk http://pastebin.com/kdCcm6yg. Give up!! =(

  • Lalo Martins

    linking to /usr/lib is a dangerous bad idea; it will break mysteriously when you update your system. Better to link to $VIRTUAL_ENV/lib.

  • http://profiles.google.com/sefklon Sef Kloninger

    Thank you, helpful.

  • http://www.facebook.com/danward.fb Dan Ward

    I also found these work, best to check in /usr/lib which gnu directory matches your setup.

    ln -s /usr/lib/arm-linux-gnueabi/libjpeg.so /usr/lib/

    ln -s /usr/lib/arm-linux-gnueabi/libfreetype.so /usr/lib/
    ln -s /usr/lib/arm-linux-gnueabi/libz.so /usr/lib/

  • mike

    this makes sense when python setup.py build_ext -i, however, when selftest.py, it still comes out the jpeg encoder not found error. not find solution, any idea