Fail during installation of Pillow (Python module) in Linux

Question:

I’m trying to install Pillow (Python module) using pip, but it throws this error:

ValueError: jpeg is required unless explicitly disabled using --disable-jpeg, aborting

So as the error says, I tried:

pip install pillow --global-option="--disable-jpeg"

But it fails with:

error: option --disable-jpeg not recognized

Any hints how to deal with it?

Asked By: mchfrnc

||

Answers:

There is a bug reported for Pillow here, which indicates that libjpeg and zlib are now required as of Pillow 3.0.0.

The installation instructions for Pillow on Linux give advice of how to install these packages. Note that not all of the following packages may be missing on your machine (comments suggest that only libjpeg8-dev is actually missing).

pip / PyPi (Pillow>3.4.2)

The latest releases of Pillow are available on PyPi as wheels — the new standard packaging mechanism for Python. These prebuilt packages include all neccessary binary dependencies to allow Pillow to run and should be used if you want to install Pillow using PyPi

To use wheels, you need to have a version of pip>=1.4. If you are using an earlier version (pip --version) upgrade pip using the following:

pip install --upgrade pip 

Once pip is upgraded, pip install will use platform-specific wheel files by default if they are available. Use the following command to upgrade Pillow to the latest version available on PyPi:

pip install --upgrade pillow

Ubuntu 12.04 LTS or Raspian Wheezy 7.0

sudo apt-get install libtiff4-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk

Ubuntu 14.04

sudo apt-get install libtiff5-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk

Ubuntu 18.04

sudo apt install libjpeg8-dev zlib1g-dev

Fedora 20

The Fedora 20 equivalent of libjpeg8-dev is libjpeg-devel.

sudo yum install libtiff-devel libjpeg-devel libzip-devel freetype-devel lcms2-devel libwebp-devel tcl-devel tk-devel

Mac OS X (via Homebrew)

On Mac OS X with Homebrew this can be fixed using:

brew install libjpeg zlib

You may also need to force-link zlib using the following:

brew link zlib --force

Update April 2019: In Mojave the above will not work and you need to run the following as taken from this bug report on Pillow

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

Update July 2016: There is no longer a formula for zlib available in the main repository (Homebrew will prompt you to install lzlib which is a different library and will not solve this problem).

There is a formula available in the dupes repository. You can either tap this repository, and install as normal:

brew tap homebrew/dupes
brew install zlib

Or you can install zlib via xcode instead, as follows:

xcode-select --install

Thanks to phoenix, Panos Angelopoulou, nelsonvarela, benjaminz and Kal in the comments

After these are installed the pip installation of Pillow should work normally.

Answered By: mfitzp

Thank you @mfitzp. In my case (CentOS) these libs are not available in the yum repo, but actually the solution was even easier. What I did:

sudo yum install python-devel
sudo yum install zlib-devel
sudo yum install libjpeg-turbo-devel

And now pillow’s installation finishes successfully.

Answered By: mchfrnc

On Raspberry pi II, I had the same problem. After trying the following, I solved the problem. The solution is:

sudo apt-get update
sudo apt-get install libjpeg-dev
Answered By: xjfengck
brew install zlib

on OS X doesn’t work anymore and instead prompts to install lzlib. Installing that doesn’t help.

Instead you install XCode Command line tools and that should install zlib

xcode-select --install
Answered By: Kal

I had the ValueError: zlib is required unless explicitly disabled using --disable-zlib but upgrading pip from 7.x to 8.y resolved the problem.

So I would try to update tools before anything else.

That can be done using:

pip install --upgrade pip
Answered By: Brambor

The alternative, if you don’t want to install libjpeg:

CFLAGS="--disable-jpeg" pip install pillow

From https://pillow.readthedocs.io/en/3.0.0/installation.html#external-libraries

Answered By: shangxiao

The quickest fix is upgrate the pip. Did worked for me:

pip install --upgrade pip
Answered By: Aman Yadav

Try

pip install pillow

If it doesn’t work, try clearing the

cache by pip install --upgrade pip

Then again run

pip install pillow

On debian / ubuntu you only need:
libjpeg62-turbo-dev

So a simple sudo apt install libjpeg62-turbo-dev
and a pip install pillow

Answered By: Dean Brown

This worked for me.

   `sudo apt-get install libjpeg-dev`
Answered By: Thomas John

This worked for me to solve jpeg and zlib error :

C:Windowssystem32>pip3 install pillow --global-option="build_e
xt" --global-option="--disable-zlib" --global-option="--disable-jpeg"
Answered By: B-shan

Working successfuly :

 sudo apt install libjpeg8-dev zlib1g-dev 
Answered By: Talha Çelik

Anyone with Python 3.9 you can only install Pillow 8.0, Any version lower than that wouldn’t work. For more check here.

So you can run it like this:

pip install Pillow==8.0.0

BTW this is tested on pip 21.0.1 (python 3.9) on MacOS Big Sur 11.2

Answered By: Mahad Ahmed
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.