About the PIL Error -- IOError: decoder zip not available
Asked Answered
A

16

70

I am getting the:

IOError: decoder zip not available

when I try to draw an image and save to a jpeg in PIL. Any thoughts on how to resolve this? PIL has worked fine for me in the past, when it comes to viewing/uploading images.

Altogether answered 23/8, 2010 at 1:14 Comment(0)
E
13

It likely only needs the zip decoder to save the jpeg. I think I needed to follow these steps in OS X to preview jpegs.

It probably means you need to:

Excalibur answered 23/8, 2010 at 1:17 Comment(2)
You could download the zlib and then just reinstall pil with pip. You shouldn't need to build it from source.Childress
Mac OS X PIL JEPG and PNG issues, This Post help me out of both PNG and JPEG issue with PIL. (decoder zip not available and decoder jpeg not available )Malca
S
116
sudo pip uninstall PIL
sudo pip install pillow 

^^ fixed it for me.

Pillow is a fork of PIL that is compatible with pip/setuptools and gets a little better maintenance. I haven't seen any API differences yet.

Edit: There is one notable API difference. PIL exposes Image as a top-level namespace, so you can

import Image # in PIL only

but

from PIL import Image  # in pillow or PIL
  • Thanks, Leopd!
Sension answered 10/9, 2012 at 21:38 Comment(6)
Fixed my problem! This is a lot simpler than compiling PIL manually. Thank you!Forland
Small API difference - import Image works in PIL, not pillow. pillow requires from PIL import ImageCano
This also solves the problem described here: osdir.com/ml/python-numeric-general/2009-07/msg00124.html where numpy array doesn't actually create an array, but something like <PngImagePlugin.PngImageFile instance at 0xd1a050> depending on the image type. I think the API change makes a lot of sense as well...Batsheva
Before running the pillow install, I would recommend installing the zlib and jpeg dev headers with "sudo apt-get install libjpeg-dev zlib1g-dev" This will ensure that .png and .jpg export work properly and are compiled in.Laager
Didn't help on OS X Mavericks :(Crowe
If you are reinstalling Pillow after installing zlib, you need to recompile Pillow: pip --no-cache-dir install PillowBigamist
B
41

The more detail installation PIL with zlib library in Ubuntu 64 bit :

http://obroll.com/install-python-pil-python-image-library-on-ubuntu-11-10-oneiric/

For the lazy (credits to @meawoppl for the apt-get):

$ sudo apt-get install libjpeg-dev zlib1g-dev
Besprent answered 10/2, 2012 at 3:8 Comment(3)
For the lazy: sudo apt-get install libjpeg-dev zlib1g-devLaager
If you happen to be developing for pebble and come here because the zip decoder not available. Install these libraries and reinstall pillow. Installing pillow again, will rebuild the library with these dependencies included.Unsteady
If this doesn't work for you, look at the answer by JohnPang which worked for me.Quattlebaum
N
17

I encountered this problem on a 64bit ubuntu 13.04 desktop version and here is how I resolved it.

try to reinstall PIL, and pay attention to the output info after you reinstalled:

---------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version       1.1.7
platform      linux2 2.7.4 (default, Sep 26 2013, 03:20:26)
              [GCC 4.7.3]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
*** ZLIB (PNG/ZIP) support not available
--- FREETYPE2 support available
*** LITTLECMS support not available
--------------------------------------------------------------------

notice that there is a line :*** ZLIB (PNG/ZIP) support not available, which means PIL have been built without ZLIB support, and I fixed it by doing this:

first you should have these packages install: libjpeg-dev libfreetype6-dev zlib1g-dev

sudo apt-get install python-dev libjpeg-dev libfreetype6-dev zlib1g-dev

# create these links, if already exists, remove it and re-link it
ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib
ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib
ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib

# reinstall PIL
pip uninstall PIL
pip install PIL

This time, there should be a line --- ZLIB (PNG/ZIP) support available in the output.

Reference: http://jj.isgeek.net/2011/09/install-pil-with-jpeg-support-on-ubuntu-oneiric-64bits/

Numeral answered 15/1, 2014 at 3:43 Comment(1)
If you see a _imagingft.c:73:31: fatal error: freetype/fterrors.h: No such file or directory error after this just link one more library: ln -s /usr/include/freetype2 /usr/include/freetype2/freetype (I believe this happens if you have apt-get install python-imaging)Boohoo
E
13

It likely only needs the zip decoder to save the jpeg. I think I needed to follow these steps in OS X to preview jpegs.

It probably means you need to:

Excalibur answered 23/8, 2010 at 1:17 Comment(2)
You could download the zlib and then just reinstall pil with pip. You shouldn't need to build it from source.Childress
Mac OS X PIL JEPG and PNG issues, This Post help me out of both PNG and JPEG issue with PIL. (decoder zip not available and decoder jpeg not available )Malca
H
9

I encountered same problem. It seems to me that Pillow and pillow (different case in 'p') are two different packages. So, if you are using Pillow, pip install pillow might not help. Here is my solution:

$ pip uninstall Pillow
$ sudo apt-get install libjpeg-dev zlib1g-dev
$ pip install -I Pillow

First two lines are to remove any pillow or Pillow package.

Third line is to install the two required packages.

Forth is re-install Pillow.

Note, if you are using virtualenv, pip install/uninstall must be run under virtualenv

Humorous answered 9/8, 2014 at 16:50 Comment(0)
E
2

The way I fixed this on OS X Mavericks was by doing this:

Install brew:

http://brew.sh/

Install pip:

http://www.pip-installer.org/en/latest/installing.html

With those in place, you can do this:

sudo brew install lzlib     # installs zlib
pip uninstall PIL
pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL

After that, it was working fine. For an explanation of the third line, check this answer:

https://mcmap.net/q/190147/-the-problem-with-installing-pil-using-virtualenv-or-buildout

Edette answered 27/1, 2014 at 15:7 Comment(0)
S
1

on mac

sudo brew install lzlib     # installs zlib
pip uninstall PIL
pip install PIL
Supremacist answered 1/1, 2014 at 21:51 Comment(2)
Please elaborate some more. It is really hard to tell what you are saying.Cicily
and sudo brew install lzlib just says "brew: command not found" on mine.Edette
C
1

I use 64bit ubuntu 14.04LTS desktop version, and I tried Johnny Zhao's answer.
When

exec sudo easy_install PIL

I got an error:

can't find freetype/fterrors.h

and I find freetype2 in /usr/include/

You could solve it by:

sudo ln -s /usr/include/freetype2 /usr/include/freetype

then install will be success

Cystocarp answered 21/9, 2014 at 8:21 Comment(1)
This happens because you have python-imaging installed with apt-get install python-imaging. If you just install libjpeg-dev libfreetype6-dev zlib1g-dev on their own without all of python-imaging, you wont get this error.Boohoo
E
1

The cause may be you've installed Pillow without zlib support.

On CentOS 7:

yum install zlib zlib-devel
pip install Pillow --upgrade

And if you are using for a webapp restart your webserver to apply.

Enjoyable answered 11/10, 2015 at 12:5 Comment(1)
This is probably obvious, but if you're using a virtualenv, the "pip install Pillow --upgrade" should be done inside the virtualenv.Jaimeejaimes
B
0

on my case, i just remore python-image, make sure that libz is ready then reinstall PIL, more detail you can see on my post here :

http://febru.soluvas.com/2014/03/solved-openerp-7-ioerror-decoder-zip.html

Ballade answered 18/3, 2014 at 7:28 Comment(0)
M
0

Mac OS X PIL JEPG and PNG issues (same for linux os), this Post help me out of both PNG and JPEG issues with PIL : decoder zip not available and decoder jpeg not available

Make sure JPEG and ZLIB are available, when you install / reinstall PIL :

$ cd Imaging-1.1.7
$ python setup.py build_ext -i
$ python selftest.py

--------------------------------------------------------------------
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
*** FREETYPE2 support not available
*** LITTLECMS support not available
--------------------------------------------------------------------
Malca answered 25/7, 2014 at 3:38 Comment(0)
M
0

I tried the version 2.8.0 it works fine me

pip install -Iv Pillow==2.8.0
Maledict answered 14/3, 2018 at 11:14 Comment(0)
S
0

On Ubuntu 18 I have had to install pillow 2.8.1:

pip install Pillow==2.8.1
Subdiaconate answered 19/5, 2018 at 9:37 Comment(0)
C
0

Try: $ sudo apt-get install python-dev $ sudo apt-get install libjpeg8-dev $ sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib Starting from version 3.0.0 Pillow needs libjpeg. If the issue persists, there might be some package incompatibility. Save some time and try the previous version: $ pip install Pillow==2.8.1

Collective answered 27/7, 2019 at 0:54 Comment(0)
S
0

On MacOS Monterey (12.2) installing rather old Pillow version 2.8.2 required following procedure:

  • I needed to install zlib first:

    brew install zlib
    
  • to get information where inludes/libs are stored:

    brew info zlib
    

    I found information as:

    For compilers to find zlib you may need to set:
    export LDFLAGS="-L/opt/homebrew/opt/zlib/lib"
    export CPPFLAGS="-I/opt/homebrew/opt/zlib/include"
    
  • I wanted to be sure so I checked if zlib.hexists:

    ls -al /opt/homebrew/opt/zlib/include/zlib.h
    
  • based on information from previous steps setup C/C++ build_ext environment variables, in my case this was:

    export LDFLAGS="-L/opt/homebrew/opt/zlib/lib"
    export CPPFLAGS="-I/opt/homebrew/opt/zlib/include"
    export CFLAGS="-I/opt/homebrew/opt/zlib/include"
    

    NOTE: I needed to add CFLAGS too, probably due C compiler is used (Pillow <=5.*), not C++.

  • finally build it (note that --no-cache-dir will force download and build):

    pip install --no-cache-dir --force "Pillow==2.8.2" 
    
  • Note that zlib is required starting with Pillow 3+, so 2.8.2 will not complain if zlib is not found (versions 3+ will stop build). Therefore after build/install is done one should test if zip_decoder is available like this:

    python -c "from PIL import _imaging as x; print(x.zip_decoder); print('OK')"
    

Additionally

Single shell command which will redownload and rebuild everyting:

LDFLAGS="-L/opt/homebrew/opt/zlib/lib" \
CPPFLAGS="-I/opt/homebrew/opt/zlib/include" \
CFLAGS="-I/opt/homebrew/opt/zlib/include" \
pip install --no-cache-dir --force "Pillow==2.8.2" 

Another alternative would be to symlink zlib include/lib files/folders to appropriate standard include/lib files/folders.

Switchback answered 29/6, 2022 at 6:55 Comment(0)
C
-1

You should match Pillow's version your python version.

Calcific answered 30/6, 2021 at 6:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.