8

I tried to install PIL on my raspberry pi and read JPEG files. However, it does not work out of the box.

When I run the following:

sudo pip install pil

I receive the following error, trying to open an Image:

""decoder jpeg not available""

While trying to install all needed JPEG libraries I ran into some errors e.g.:

sudo apt-get install libjpeg
E: Unable to locate package libjpeg
m3o
  • 3,881
  • 3
  • 35
  • 56

1 Answers1

18

You have to re-install PIL and also install the needed libraries as well as link them manually. This answer is based on this blog post for a regular ubuntu PIL installation and this askubuntu question, where it is explained how to compile the jpeg encoding:

### uninstall PIL
sudo pip uninstall pil

### download and compile the JPEG library
wget http://www.ijg.org/files/jpegsrc.v8c.tar.gz    
tar xvfz jpegsrc.v8c.tar.gz
cd jpeg-8c
./configure --enable-shared --prefix=$CONFIGURE_PREFIX
make
sudo make install

### link the libraries correctly - RASPBERRY PI ONLY
sudo ln -s /usr/lib/arm-linux-gnueabi/libjpeg.so /usr/lib
sudo ln -s /usr/lib/arm-linux-gnueabi/libfreetype.so /usr/lib
sudo ln -s /usr/lib/arm-linux-gnueabi/libz.so /usr/lib

### install rest of the libraries, as well as freetrype and zlib
sudo apt-get install libjpeg-dev libfreetype6 libfreetype6-dev zlib1g-dev

### re-install PIL
sudo pip install pil

hope that helps someone!

Community
  • 1
  • 1
m3o
  • 3,881
  • 3
  • 35
  • 56
  • I tried but got support available for freetype2 and ZLIB(png/zip) not for jpeg and tkinter. Any idea what could possibly went wrong ? – Cugomastik Jul 16 '14 at 12:30
  • Thanks! I had to install using [this command](http://stackoverflow.com/a/21243133/1167783), since PIL has now been replaced with Pillow: `pip install PIL --allow-external PIL --allow-unverified PIL` – JeffThompson Jun 12 '15 at 01:21
  • Thank you, worked like a charm. I used `pip install pillow` instead of `pip install pil`. – Leistungsabfall Aug 19 '15 at 18:27
  • 5
    In case it should help future readers, the only part I needed was `sudo apt-get install libjpeg-dev libfreetype6 libfreetype6-dev zlib1g-dev` – Mark Smith Jan 15 '17 at 17:16