15

I am following a Django tutorial that involves image uploading, and have run into this problem. I tried installing and reinstalling PIL, libjpeg, and libfreetype6 several times, but nothing so far seems to be working. I have spent several hours trying to find a solution, and am very frustrated at this point. Please help.

Here is the result of selftest.py after I reinstall PIL on my mac:

PIL 1.1.6 BUILD SUMMARY
--------------------------------------------------------------------
version       1.1.6
platform      darwin 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43)
              [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
--------------------------------------------------------------------
--- TKINTER support ok
*** JPEG support not available
--- ZLIB (PNG/ZIP) support ok
*** FREETYPE2 support not available
--------------------------------------------------------------------
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.

To check the build, run the selftest.py script.
rrdhcp-10-32-44-157:Imaging-1.1.6 pfg$ python selftest.py
*****************************************************************
Failure in example: _info(Image.open("Images/lena.jpg"))
from line #24 of selftest.testimage
Exception raised:
Traceback (most recent call last):
  File "./doctest.py", line 499, in _run_examples_inner
    exec compile(source, "<string>", "single") in globs
  File "<string>", line 1, in <module>
  File "./selftest.py", line 22, in _info
    im.load()
  File "PIL/ImageFile.py", line 180, in load
    d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
  File "PIL/Image.py", line 375, in _getdecoder
    raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available
1 items had failures:
   1 of  57 in selftest.testimage
***Test Failed*** 1 failures.
*** 1 tests of 57 failed.
entrepaul
  • 927
  • 3
  • 12
  • 23
  • 2
    you need to install jpeg libs before installing PIL, there are many instructions how to do this, eg: http://stackoverflow.com/questions/8915296/decoder-jpeg-not-available-pil – dzida Sep 23 '12 at 20:09
  • If you are on a Mac, you can use [Brew](http://mxcl.github.com/homebrew/) to easily install libjpeg. I ran in to difficulty before, and [this link](http://timetobefrank.blogspot.com.es/2011/05/installing-pil-on-mac-osx-with.html) also helped. – Timmy O'Mahony Sep 23 '12 at 20:49
  • Lukasz, I removed PIL, installed libfreetype, zlib, and libjpeg - then reinstalled PIL, and am still getting the same exact error on selftest.py... – entrepaul Sep 23 '12 at 20:51

4 Answers4

42

There are several cases with PIL which lead to a similar experience. If you have installed PIL out of a virtualenv using

pip install PIL

Then you should have installed the dev versions of libjpeg, libz before. Assuming you're on a Ubuntu box, a

pip uninstall PIL
apt-get install libjpeg-dev zlib1g-dev libpng12-dev
pip install PIL

should suffice. You could also install Pillow instead of PIL, it works better with setuptools and can be installed in a virtualenv.

Community
  • 1
  • 1
Steve K
  • 10,879
  • 4
  • 39
  • 39
7

I found this worked fine for me:

pip uninstall PIL
pip install Pillow

then I restarted the server:

kill -HUP XXX

where XXX is the process ID of the your server process.

Hawkz
  • 71
  • 1
  • 2
5

I was already using Pillow and got the same error. Tried installing libjpeg or libjpeg-dev as suggested by others but was told that a (newer) version was already installed.

In the end all it took was reinstalling Pillow:

sudo pip uninstall Pillow
sudo pip install Pillow
Dimitris
  • 13,480
  • 17
  • 74
  • 94
0

In case you are using Fedora, please do, before doing a pip install Pillow:

yum install libjpeg-devel zlib1g-devel libpng12-devel
Joepreludian
  • 980
  • 9
  • 11