304

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?

FlipMcF
  • 11,666
  • 2
  • 31
  • 43
Ravi
  • 2,432
  • 3
  • 15
  • 25
  • 22
    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. – neves Oct 09 '13 at 23:19
  • 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 Nov 14 '13 at 22:44
  • Ok, Fine. I edited the question to fit in the rules of SO. Hopefully, @ravi doesn't mind the edit. – FlipMcF Nov 14 '13 at 22:57
  • 1
    Maybe you can read this and try it: http://stackoverflow.com/questions/18504835/pil-decoder-jpeg-not-available-on-ubuntu-x64/20091508#20091508 – Wee Nov 20 '13 at 09:10
  • 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. – Dhiraj Thakur Jan 23 '14 at 08:01
  • 1
    @dkt I'm using pillow and am here because I just hit this issue. – Stephen Tetreault Feb 22 '14 at 23:50
  • @SMT : In that case use the excellent answers below, i just wanted inform anyone who is new about pillow. – Dhiraj Thakur Feb 23 '14 at 17:55
  • 1
    @dkt I know, I was just stating that the issue still persists was all. – Stephen Tetreault Feb 23 '14 at 22:51
  • @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. – Christos Hayward May 25 '16 at 20:14

15 Answers15

491

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).

gregoltsov
  • 2,149
  • 1
  • 21
  • 36
Rolo
  • 6,030
  • 1
  • 19
  • 12
  • 1
    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. – Ravi Apr 26 '12 at 12:23
  • 2
    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/ – Charles Offenbacher Feb 02 '13 at 02:59
  • 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. – John F. May 06 '13 at 23:35
  • 2
    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. – Dhiraj Thakur Jan 23 '14 at 08:02
  • I had to install `sudo apt-get install libjpeg8-dev` additionally to get it to work. – rkrzr Mar 21 '14 at 13:07
  • 1
    @Rolo after 3 hr your second option worked for me thanks lot the pillow is dumbass – Akshay Mukadam Aug 05 '14 at 10:21
  • 1
    this works like a charm on Ubuntu 14-04 with django 1.7 – Chris Hawkes Jan 14 '15 at 23:32
  • FYI: `pip uninstall pillow` and `pip install pillow` works but `pip install -I pillow` didn't work. – zengr Mar 11 '15 at 18:02
  • 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. – Agey Jun 19 '15 at 14:27
  • 5
    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! – t-mart Jul 08 '15 at 17:13
  • I haf similar problem with Pillow, and this solution is also working – ismailsunni Oct 07 '15 at 03:23
  • 1
    Currently apt-get install libjpeg-dev also installs libjpeg8-dev – Berk Jan 03 '17 at 16:38
  • 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. – George Sep 03 '17 at 21:04
  • 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. – Jason McCarrell Feb 13 '18 at 20:46
  • only doing this worked for me. pip install --no-cache-dir -I pillow – Junaid Jul 11 '18 at 10:18
64

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
Community
  • 1
  • 1
zeantsoi
  • 23,793
  • 7
  • 62
  • 61
  • I had this problem after upgrading to Mavericks (10.9). The following [SO post](http://stackoverflow.com/questions/19532125/cant-install-pil-after-mac-os-x-10-9) solved the problem for me. Scroll down to the **install command line tools** comment by @Formulka – tatlar Nov 13 '13 at 18:06
  • 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. – deadlock Apr 03 '14 at 02:24
  • I got this error: Could not find any donwnloads that satisfy the requirement pil – RicardoGonzales Apr 24 '14 at 20:46
  • @RicardoGonzales, you're probably running on a version of pip the requires you to pass additional flags. Please see the update to my answer. – zeantsoi Apr 24 '14 at 20:56
  • @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? – RicardoGonzales Apr 24 '14 at 21:17
  • @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 – RicardoGonzales Apr 24 '14 at 21:33
  • 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!! – Packet Tracer Oct 23 '14 at 09:53
  • didn't work for me on Yosemite, I get _imagingft.c:73:10: fatal error: 'freetype/fterrors.h' file not found – DataGreed Jun 22 '15 at 10:45
29

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
Dennis Golomazov
  • 12,909
  • 4
  • 67
  • 73
  • I did this some time ago, and suddenly the error reappeared today. Upgrading pillow fixed the problem: `pip install pillow --upgrade`. – Dennis Golomazov Aug 11 '15 at 14:29
22

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!!

Ambar
  • 35
  • 8
Jason Huang
  • 249
  • 3
  • 4
  • 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. http://stackoverflow.com/questions/18504835/pil-decoder-jpeg-not-available-on-ubuntu-x64 – Lucas Ou-Yang Aug 29 '13 at 11:20
  • Protip for everybody, libjpeg-dev must be installed _before_ Pillow is installed. – Kurt Nov 11 '20 at 18:27
17

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
Bengt
  • 12,424
  • 6
  • 43
  • 65
14

Rolo's answer is excellent, however I had to reinstall Pillow by bypassing pip cache (introduced with pip 7) otherwise it won't get properly recompiled!!! The command is:

pip install -I --no-cache-dir -v Pillow

and you can see if Pillow has been properly configured by reading in the logs this:

PIL SETUP SUMMARY
    --------------------------------------------------------------------
    version      Pillow 2.8.2
    platform     linux 3.4.3 (default, May 25 2015, 15:44:26)
                 [GCC 4.8.2]
    --------------------------------------------------------------------
    *** TKINTER support not available
    --- JPEG support available
    *** OPENJPEG (JPEG2000) support not available
    --- ZLIB (PNG/ZIP) support available
    --- LIBTIFF support available
    --- FREETYPE2 support available
    *** LITTLECMS2 support not available
    *** WEBP support not available
    *** WEBPMUX support not available
    --------------------------------------------------------------------

as you can see the support for jpg, tiff and so on is enabled, because I previously installed the required libraries via apt (libjpeg-dev libpng12-dev libfreetype6-dev libtiff-dev)

daveoncode
  • 16,281
  • 13
  • 90
  • 146
12

On Mac OS X Mavericks (10.9.3), I solved this by doing the follows:

Install libjpeg by brew (package management system)

brew install libjpeg

reinstall pillow (I use pillow instead of PIL)

pip install -I pillow

moogoo
  • 331
  • 3
  • 8
  • 2
    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. – Lucas Jun 17 '14 at 17:50
11
apt-get install libjpeg-dev
apt-get install libfreetype6-dev
apt-get install zlib1g-dev
apt-get install libpng12-dev

Install these and be sure to install PIL with pip because I compiled it from source and for some reason it didn't work

EMP
  • 111
  • 1
  • 2
  • List of all required [dependencies](https://pillow.readthedocs.org/en/latest/installation.html#linux-installation). – Paolo Jul 06 '15 at 09:12
9

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
  • 12,954
  • 17
  • 71
  • 93
3

I'm too newbie to comment zeantsoi post ;(. So here his what I needed to do to solved on OSX on 10.9.1 the

IOError: decoder jpeg not available

1) install Xcode tools (open your terminal and execute: xcode-select --install) - taken from this post: Can't install PIL after Mac OS X 10.9

2) install libpng and libjpeg package (combo installer) from this link: http://ethan.tira-thompson.com/Mac_OS_X_Ports.html

3) reboot (not sure it was mandatory)

4) Re-install PIL with run pip install -I PIL (as I had initially installed PIL before having the issue)

Hope this help and don't confuse more ...

_oho

Community
  • 1
  • 1
oho
  • 61
  • 4
2

This question was posted quite a while ago and most of the answers are quite old too. So when I spent hours trying to figure this out, nothing worked, and I tried all suggestions in this post.

I was still getting the standard JPEG errors when trying to upload a JPG in my Django avatar form:

raise IOError("decoder %s not available" % decoder_name)
OSError: decoder jpeg not available

Then I checked the repository for Ubuntu 12.04 and noticed some extra packages for libjpeg. I installed these and my problem was solved:

sudo apt-get install libjpeg62 libjpeg62-dev

Installing these removed libjpeg-dev, libjpeg-turbo8-dev, and libjpeg8-dev.

Hope this helps someone in the year 2015 and beyond!

Cheers

nicorellius
  • 3,015
  • 4
  • 40
  • 74
1

Same problem here, JPEG support available but still got IOError: decoder/encoder jpeg not available, except I use Pillow and not PIL.

I tried all of the above and more, but after many hours I realized that using sudo pip install does not work as I expected, in combination with virtualenv. Silly me.

Using sudo effectively launches the command in a new shell (my understanding of this may not be entirely correct) where the virtualenv is not activated, meaning that the packages will be installed in the global environment instead. (This messed things up, I think I had 2 different installations of Pillow.)

I cleaned things up, changed user to root and reinstalled in the virtualenv and now it works.
Hopefully this will help someone!

kaka
  • 1,148
  • 1
  • 13
  • 15
1

For Fedora

Install pre-requisite
sudo dnf install make automake gcc gcc-c++ kernel-devel rpm-build libjpeg-devel zlib-devel python-devel
Now install Pillow

sudo pip install pillow

Note - For libjpeg and zlib we are installing libjpeg-devel and zlib-devel packages in Fedora/CentOS/Red Hat

Ajinkya Bhosale
  • 183
  • 2
  • 8
0

First I had to delete the python folders in hidden folder user/appData (that was creating huge headaches), in addition to uninstalling Python. Then I installed WinPython Distribution: http://code.google.com/p/winpython/ which includes PIL

Jill
  • 1
  • 2
0

For those on Mac OS Mountain Lion, I followed the anwser of zeantsoi, but it doesn't work.

I finally ended up with the solution of this post: http://appelfreelance.com/2010/06/libjpeg-pil-snow-leopard-python2-6-_jpeg_resync_to_restart/

Now, I'm happily running my script for jpeg !

Zhenyi Zhang
  • 1,167
  • 9
  • 7