How to install PIL in Ubuntu 11.04?
Solution 1
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...
Solution 2
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
Solution 3
Try reinstalling from scratch:
Look for lib/pythonXX/site-packages/PIL. Delete all this directory along with the file PIL.pth. This should completely remove te package.
Unpack the PIL installation files from the *tar.gz you downloaded.
Add the directories where your jpeg library is, with add_directory(...) as you did before. (Use ldconfig -P | grep jpeg to find where the libraries are).
Retry python setup.py build, then python setup.py install. Test it.
My experience was:
Not performing step 2 did not rebuild the package. Not performing step 3 was the root cause. Not performing step 1 may have played a part.
This seems to be a bug in PIL installation, not in Ubuntu's or any distro's package structure.
And just for the record: it is quite common to have more than one Python version installed on a system, which makes it necessary to install packages manually. Some people have a 2.x with a 3.x for experimenting, shared hostings have 2.5s and applications need a 2.7, just to give two examples.
Comments
-
john2x almost 2 years
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 >>>
-
john2x over 12 yearsJust tried it, but still getting the decoder error. Did my fiddling around mess it up somehow? I already removed the
site-packages/PIL
files. Also, how do install it for both 2.5 and 2.7? (2.5 for Google App Engine) -
Gareth Latty over 12 yearsWhen are you getting this error? It doesn't sound like an import error - and if it isn't, your problem is not the installation, but within PIL or it's dependencies. This may be a bug with the package, and if so - you should file a bug report. As to 2.5, I'm not sure how Ubuntu handles old versions of software, so I'm afraid I can't answer that one for you.
-
john2x over 12 yearsI updated the original post to see how I test if it's working or not. Basically, I open an image, and rotate it. Rotating it uses the decoder, that's where I get the error.
-
Gareth Latty over 12 years@john2x It looks like there is indeed a problem with the Ubuntu packages: ubuntuforums.org/showthread.php?t=1751455