About the PIL Error -- IOError: decoder zip not available

Viewed 59345

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.

16 Answers

On Ubuntu 18 I have had to install pillow 2.8.1:

pip install Pillow==2.8.1

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

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.

You should match Pillow's version your python version.

Related