Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How do I install the python imaging library (PIL) on Ubuntu?

I tried doing

sudo apt-get install python-imaging

but now when i run python selftest.py (a script I got from somewhere on the http://pythonware.com/products/pil/ website) I get (among other warning messages):

...
*** JPEG support not installed
*** ZLIB (PNG/ZIP) support not installed
...
*** 1 tests of 57 failed.

Have I somehow messed up the PIL -- how do I fix that?

Is maybe the PIL just fine, but that "selftest.py" is not really the right program for checking to see if PIL is installed properly -- how else can I tell if PIL is installed properly or not?

(I'm using Ubuntu 12.04 LTS "Precise Pangolin").

(What I'm ultimately trying to do is to add a 2D barcode generator to some python code, and all the 2D barcode generators I could find that were written in python all seemed to use the PIL).

share|improve this question
1  
You might want to try using the PIL in an application, there might just be a problem with selftest.py –  Aaron Jun 26 '12 at 23:28

4 Answers 4

up vote 16 down vote accepted

Something similar happened to me, I solved this way

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

And try there installing via pip install PIL.

More on what pip is can be found here. In short is a convenient (and becoming a standard) way of installing python libraries.

if it continues to fail, it can be due to PIL searching those libraries in a different path.

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.

Try to see if libjpeg and libz libs exist in /usr/lib/x86_64-linux-gnu and make a symlink this way

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

Source: http://jj.isgeek.net/2011/09/install-pil-with-jpeg-support-on-ubuntu-oneiric-64bits/

share|improve this answer
    
This did not work for me on Ubuntu 12.04 64bit. –  Gus E May 22 '13 at 20:03
1  
if it fits your needs, you could try 'pillow'. It is a drop in replacement for PIL. –  Hernantz May 23 '13 at 15:05
2  
Whenever possible, use pillow. It's essentially PIL but actually maintained. –  Thane Brimhall Oct 9 '13 at 19:39

The above solution did not work for me on Ubuntu 12.10 as libjpeg was not available in the repository.

What did end up working for me was:

sudo apt-get build-dep python-imaging
sudo apt-get install libjpeg62 libjpeg62-dev

If you get the error "You must put some 'source' URIs in your sources.list" then make sure that your /etc/apt/sources.list has deb-src entries which match your deb entries.

Then you must symlink the files from their actual location on your server to the location where PIL expects them.

32-bit version

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

64-bit version

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

Finally, pip install PIL

Success!

enter image description here


Update Sep 2014

Pillow is a more modern fork of PIL.

#jpeg support
sudo apt-get install libjpeg-dev
#tiff support
sudo apt-get install libtiff-dev
#freetype support
sudo apt-get install libfreetype6-dev
#openjpeg200support (needed to compile from source)
wget http://downloads.sourceforge.net/project/openjpeg.mirror/2.0.1/openjpeg-2.0.1.tar.gz
tar xzvf openjpeg-2.0.1.tar.gz
cd openjpeg-2.0.1/
sudo apt-get install cmake
cmake .
sudo make install
#install pillow
pip install pillow
share|improve this answer
1  
Works for me on 13.04 with Pillow, without symlinking. –  Eugene Nagorny Oct 29 '13 at 5:23

I just want to add, that pip install pill no longer works, at least on my machine, you have to do

pip install PIL --allow-external PIL --allow-unverified PIL

share|improve this answer

The above answers create links for x64 libraries in x86 locations. Instead I would download the PIL source then add these lines in setup.py:

    add_directory(library_dirs, "/usr/lib/x86_64-linux-gnu")
    add_directory(library_dirs, "/lib/x86_64-linux-gnu")

after these lines (~line 211)

    # standard locations
    add_directory(library_dirs, "/usr/local/lib")
    add_directory(include_dirs, "/usr/local/include")

    add_directory(library_dirs, "/usr/lib")
    add_directory(include_dirs, "/usr/include")

reinstall PIL. If you're using pip:

pip uninstall PIL

Then from the source directory run:

python setup.py install
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.