Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install PIL in Ubuntu 11.04?

I see this question asked all over the internet, and I've tried following them all, but I still can't get PIL to work.

I tried symbolically linking the zlib, jpeg, etc. libraries via:

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/
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/

I tried editing the setup.py file, adding this line:

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

In fact, running $ sudo python setup.py install shows that JPEG, ZLIB/PNG, etc. support is Available. (I'm installing it for both 2.5 and 2.7, works in neither)

sudo python2.5 setup.py install
running install
running build
running build_py
running build_ext
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version       1.1.7
platform      linux2 2.5.6 (r256:88840, Feb  1 2012, 15:55:08)
              [GCC 4.5.2]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
--- LITTLECMS support available

But after all that, I still get a decoder %s not available error.

I'm at my wits end. Anything else I might have missed?

My environment: 64-bit Ubuntu 11.04 running in a VirtualBox VM.

Here's what I do to test if PIL works or not

$ python
>>> from PIL import Image
>>> im = Image.open("photo.jpg")
>>> im.rotate(45)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 1359, in rotate
  self.load()
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFile.py", line 189, in load
  d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 385, in _getdecoder
  raise IOError("decoder %s not available" % decoder_name)
IOError: decoder zip not available
>>> 
like image 675
john2x Avatar asked Feb 10 '12 09:02

john2x


2 Answers

As always, use the package manager:

sudo apt-get install python-imaging

It'll deal with it all for you. The packages are available.

Manually installing, in any Linux distro, is a wasted endeavour, unless the packages really don't exist. Package maintainers spend time ensuring that the package works and installs correctly, there is no point duplicating their effort. Especially not to manually install something that then doesn't have the advantages of a package - no automatic updating, no easy removal, etc...

like image 68
Gareth Latty Avatar answered Nov 12 '22 16:11

Gareth Latty


I have successfully reinstalled PIL in Ubuntu 12.04 like this:

pip uninstall PIL
apt-get install libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev
ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib/
ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/
ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/
pip install -U PIL

It does not raise the IOError: decoder zip not available anymore after reinstalling the PIL. My error traceback was:

Traceback (most recent call last):
  File "convert_image.py", line 15, in <module>
    image.save('output.png')
  File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 1406, in save
    self.load()
  File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFile.py", line 189, in load
    d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
  File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 385, in _getdecoder
    raise IOError("decoder %s not available" % decoder_name)
IOError: decoder zip not available
like image 2
niekas Avatar answered Nov 12 '22 17:11

niekas