Python Image Library fails with message "decoder JPEG not available" - PIL

156,357

Solution 1

libjpeg-dev is required to be able to process jpegs with pillow (or PIL), so you need to install it and then recompile pillow. It also seems that libjpeg8-dev is needed on Ubuntu 14.04

If you're still using PIL then you should really be using pillow these days though, so first pip uninstall PIL before following these instructions to switch, or if you have a good reason for sticking with PIL then replace "pillow" with "PIL" in the below).

On Ubuntu:

# install libjpeg-dev with apt
sudo apt-get install libjpeg-dev
# if you're on Ubuntu 14.04, also install this
sudo apt-get install libjpeg8-dev

# reinstall pillow
pip install --no-cache-dir -I pillow

If that doesn't work, try one of the below, depending on whether you are on 64bit or 32bit Ubuntu.

For Ubuntu x64:

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

Or for Ubuntu 32bit:

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

Then reinstall pillow:

pip install --no-cache-dir -I pillow

(Edits to include feedback from comments. Thanks Charles Offenbacher for pointing out this differs for 32bit, and t-mart for suggesting use of --no-cache-dir).

Solution 2

For those on OSX, I used the following binary to get libpng and libjpeg installed systemwide:

libpng & libjpeg for OSX

Because I already had PIL installed (via pip on a virtualenv), I ran:

pip uninstall PIL
pip install PIL --upgrade

This resolved the decoder JPEG not available error for me.

UPDATE (4/24/14):

Newer versions of pip require additional flags to download libraries (including PIL) from external sources. Try the following:

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

See the following answer for additional info: pip install PIL dont install into virtualenv

UPDATE 2:

If on OSX Mavericks, you'll want to set the ARCHFLAGS flag as @RicardoGonzales comments below:

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install PIL --allow-external PIL --allow-unverified PIL

Solution 3

This is the only way that worked for me. Installing packages and reinstalling PIL didn't work.

On ubuntu, install the required package:

sudo apt-get install libjpeg-dev

(you may also want to install libfreetype6 libfreetype6-dev zlib1g-dev to enable other decoders).

Then replace PIL with pillow:

pip uninstall PIL
pip install pillow

Solution 4

The followed works on ubuntu 12.04:

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

when your see "-- JPEG support avaliable" that means it works.

But, if it still doesn't work when your edit your jpeg image, check the python path !! my python path missed /usr/local/lib/python2.7/dist-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/, so I edit the ~/.bashrc add the following code to this file:

Edit: export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/dist-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/

then, finally, it works!!

Solution 5

On Fedora 17 I had to install libjpeg-devel and afterwards reinstall PIL:

sudo yum install --assumeyes libjpeg-devel
sudo pip-python install --upgrade PIL
Share:
156,357

Related videos on Youtube

Ravi
Author by

Ravi

Updated on April 22, 2020

Comments

  • Ravi
    Ravi about 4 years

    PIL does support JPEG in my system.

    Whenever I do an upload, my code is failing with:

    File "PIL/Image.py", line 375, in _getdecoder
        raise IOError("decoder %s not available" % decoder_name)
    IOError: decoder jpeg not available
    

    How can I resolve this?

    • Naypa
      Naypa over 10 years
      It is a valid question. PIL is a famous Python Library and it gives a weird error in some linux systems. This question and the answer just helped me. It is a typical SO question.
    • FlipMcF
      FlipMcF over 10 years
      The PRAGMATIST and OCD in me says it does belong on ServerFault, not on SO. But how many programmers have hit this problem? I vote to move the question to ServerFault, and leave a redirect in place on SO.
    • FlipMcF
      FlipMcF over 10 years
      Ok, Fine. I edited the question to fit in the rules of SO. Hopefully, @ravi doesn't mind the edit.
    • Wee
      Wee over 10 years
      Maybe you can read this and try it: stackoverflow.com/questions/18504835/…
    • Dhiraj Thakur
      Dhiraj Thakur over 10 years
      For anyone who's just starting out with PIL should note that is outdated and not really maintained anymore. If you want to work with images in your project, use PILLOW which is updated and maintained fork or PIL.
    • Stephen Tetreault
      Stephen Tetreault over 10 years
      @dkt I'm using pillow and am here because I just hit this issue.
    • Dhiraj Thakur
      Dhiraj Thakur over 10 years
      @SMT : In that case use the excellent answers below, i just wanted inform anyone who is new about pillow.
    • Stephen Tetreault
      Stephen Tetreault over 10 years
      @dkt I know, I was just stating that the issue still persists was all.
    • Christos Hayward
      Christos Hayward about 8 years
      @FlipMcF A question should be migrated from StackOverflow to ServerFault, not primarily because it would be in scope for ServerFault, but because it is out of scope for StackOverflow's focus on helping programmers. This is the principle why questions people asked on StackOverflow about software that would let them use old versions of Internet Exploder should not be migrated to SuperUser. Questions about accessing program X are in scope for SuperUser, but that doesn't mean that they are out of scope on StackOverflow as many web developers have spent much time on appeasing Exploder.
  • Ravi
    Ravi about 12 years
    The problem was that I had two python packages. One that ships in with ubuntu and another that belonged to Zope Server. Somehow, the library was corrupted because I had incorrectly installed it in the wrong package. Otherwise, there is no problem.
  • Charles Offenbacher
    Charles Offenbacher over 11 years
    For the record, that only works on x86_64, I had to run: sudo ln -s /usr/lib/i386-linux-gnu/libz.so /usr/lib/; sudo ln -s /usr/lib/i386-linux-gnu/libfreetype.so.6 /usr/lib/; sudo ln -s /usr/lib/i386-linux-gnu/libjpeg.so /usr/lib/
  • John F.
    John F. about 11 years
    Just wanted to add that I upgraded from Ubuntu 12.10 to 13.04 and had to create the symlinks like described under the Ubuntu x64 section. That worked for me.
  • Thorin Schiffer
    Thorin Schiffer almost 11 years
    Python development under windows is painful. I'd advise not to.
  • Lucas Ou-Yang
    Lucas Ou-Yang almost 11 years
    hi, i think i'm having an issue with the python path not working because installing PIL stats that --JPEG support IS available. however, actually doing pil opts with .jpeg images causes decoder jpeg errors. stackoverflow.com/questions/18504835/…
  • tatlar
    tatlar over 10 years
    I had this problem after upgrading to Mavericks (10.9). The following SO post solved the problem for me. Scroll down to the install command line tools comment by @Formulka
  • Dhiraj Thakur
    Dhiraj Thakur over 10 years
    For anyone who's just starting out with PIL should note that is outdated and not really maintained anymore. If you want to work with images in your project, use PILLOW which is updated and maintained fork or PIL.
  • rkrzr
    rkrzr about 10 years
    I had to install sudo apt-get install libjpeg8-dev additionally to get it to work.
  • deadlock
    deadlock about 10 years
    If you're on Ubuntu 12.04 64 bit, try zeantsoi's solution, I know he did it for OSX but I tried it and it worked for me.
  • napstercake
    napstercake about 10 years
    I got this error: Could not find any donwnloads that satisfy the requirement pil
  • zeantsoi
    zeantsoi about 10 years
    @RicardoGonzales, you're probably running on a version of pip the requires you to pass additional flags. Please see the update to my answer.
  • napstercake
    napstercake about 10 years
    @zeantsoi now is downloading the package and install but after "Cleaning up" message. I got the error refers to: "-c import setuptools, tokenize;__file ... ..." any advice?
  • napstercake
    napstercake about 10 years
    @zeantsoi ok I've found the solution with args for OSX Maverics: ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error‌​-in-future pip install PIL --allow-external PIL --allow-unverified PIL
  • Lucas
    Lucas almost 10 years
    This might be due to a separate problem with my installation of brew, but I had to brew unlink jpeg && brew link jpeg before installing Pillow.
  • Akshay Mukadam
    Akshay Mukadam almost 10 years
    @Rolo after 3 hr your second option worked for me thanks lot the pillow is dumbass
  • Packet Tracer
    Packet Tracer over 9 years
    after a lot of searching this worked for me in ubuntu. I installed pil with easyinstall and pillow with pip in a virtualenv but couldn't get it working. But with this pip install PIL --allow-external PIL --allow-unverified PIL it worked. Thanks!!
  • Jakub Roztocil
    Jakub Roztocil over 9 years
    The same goes for RHEL/CentOS.
  • Chris Hawkes
    Chris Hawkes over 9 years
    this works like a charm on Ubuntu 14-04 with django 1.7
  • zengr
    zengr about 9 years
    FYI: pip uninstall pillow and pip install pillow works but pip install -I pillow didn't work.
  • Agey
    Agey almost 9 years
    I had the same problem after trying this, but after searching i found that the server had python-imaging installed from aptitude, and installed as well in pip as global. I had to remove those as well before trying the solution mentioned here.
  • DataGreed
    DataGreed almost 9 years
    didn't work for me on Yosemite, I get _imagingft.c:73:10: fatal error: 'freetype/fterrors.h' file not found
  • Paolo
    Paolo almost 9 years
    List of all required dependencies.
  • t-mart
    t-mart almost 9 years
    Recent versions of pip must cache downloaded packages and their compilations. Certainly, it was a very lengthy to pip install things the first time, but then subsequent uninstalls and (re)installs were suspiciously quick. Anyway, the methods above did not work for me until I ran pip install --no-cache-dir pillow. Good luck!
  • dranxo
    dranxo almost 9 years
    Thanks for this. The --no-cache-dir option helped me as well
  • Dennis Golomazov
    Dennis Golomazov almost 9 years
    I did this some time ago, and suddenly the error reappeared today. Upgrading pillow fixed the problem: pip install pillow --upgrade.
  • ismailsunni
    ismailsunni over 8 years
    I haf similar problem with Pillow, and this solution is also working
  • Berk
    Berk over 7 years
    Currently apt-get install libjpeg-dev also installs libjpeg8-dev
  • George
    George over 6 years
    My problem was that python used default 2.7 version, and pip installed for version 2.7, while my project was supposed to use python 3 and pip3.
  • Sophie McCarrell
    Sophie McCarrell over 6 years
    I personally just needed to uninstall and reinstall pillow. Strangely that's it. And this was on a new server, so im not sure why it didn't work the first time... perhaps the order of installation was incorrect.
  • Junaid
    Junaid almost 6 years
    only doing this worked for me. pip install --no-cache-dir -I pillow
  • Kurt
    Kurt over 3 years
    Protip for everybody, libjpeg-dev must be installed before Pillow is installed.