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

15

305

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?

Philomenaphiloo answered 18/1, 2012 at 18:24 Comment(9)
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.Spirant
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.Yehudi
Ok, Fine. I edited the question to fit in the rules of SO. Hopefully, @ravi doesn't mind the edit.Yehudi
Maybe you can read this and try it: #18505335Varico
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.Swordbill
@dkt I'm using pillow and am here because I just hit this issue.Spearwort
@SMT : In that case use the excellent answers below, i just wanted inform anyone who is new about pillow.Swordbill
@dkt I know, I was just stating that the issue still persists was all.Spearwort
@Yehudi 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.Quadragesima
A
493

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

Antonomasia answered 11/4, 2012 at 16:22 Comment(15)
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.Philomenaphiloo
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/Beastings
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.Tiffa
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.Swordbill
I had to install sudo apt-get install libjpeg8-dev additionally to get it to work.Circumambulate
@Antonomasia after 3 hr your second option worked for me thanks lot the pillow is dumbassOutgoing
this works like a charm on Ubuntu 14-04 with django 1.7Entrammel
FYI: pip uninstall pillow and pip install pillow works but pip install -I pillow didn't work.Danuloff
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.Burger
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!Flavin
I haf similar problem with Pillow, and this solution is also workingMarrowfat
Currently apt-get install libjpeg-dev also installs libjpeg8-devThapsus
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.Wightman
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.Publus
only doing this worked for me. pip install --no-cache-dir -I pillowHallmark
M
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
Meadow answered 30/10, 2012 at 16:32 Comment(8)
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 @FormulkaAssumptive
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.Oilcup
I got this error: Could not find any donwnloads that satisfy the requirement pilOpinicus
@RicardoGonzales, you're probably running on a version of pip the requires you to pass additional flags. Please see the update to my answer.Meadow
@Meadow 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?Opinicus
@Meadow 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 PILOpinicus
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!!Stivers
didn't work for me on Yosemite, I get _imagingft.c:73:10: fatal error: 'freetype/fterrors.h' file not foundHysterotomy
P
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
Protect answered 4/6, 2013 at 11:36 Comment(1)
I did this some time ago, and suddenly the error reappeared today. Upgrading pillow fixed the problem: pip install pillow --upgrade.Protect
R
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!!

Refraction answered 4/6, 2013 at 2:3 Comment(2)
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. #18505335Windermere
Protip for everybody, libjpeg-dev must be installed before Pillow is installed.Lode
P
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
Potbellied answered 3/2, 2013 at 17:35 Comment(1)
The same goes for RHEL/CentOS.Lea
R
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)

Romanesque answered 13/6, 2015 at 18:16 Comment(1)
Thanks for this. The --no-cache-dir option helped me as wellPretermit
Z
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

Zamboanga answered 5/6, 2014 at 20:16 Comment(1)
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.Pectize
F
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

Fenton answered 5/11, 2014 at 11:9 Comment(1)
List of all required dependencies.Rossini
L
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
Lamas answered 20/8, 2014 at 13:34 Comment(0)
A
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

Adan answered 28/2, 2014 at 9:27 Comment(0)
F
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

Fabien answered 5/6, 2015 at 18:55 Comment(0)
W
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!

Waterman answered 16/9, 2013 at 20:2 Comment(0)
H
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

Hex answered 13/4, 2016 at 10:7 Comment(0)
P
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

Plessor answered 5/2, 2013 at 22:51 Comment(1)
Python development under windows is painful. I'd advise not to.Dentate
L
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 !

Lyons answered 24/7, 2013 at 20:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.