6

I am trying to run a Python program with pyautogui but there's a problem because it is telling me that Pillow is not installed. I tried to install it or upgrade it with commands such as

pip install Pillow --upgrade 

but nothing worked.

On the documentation they say that Pillow doesn't coexist with PIL so we need to uninstall it but I can't because it says that it is not installed.

The error is:

The headers or library files could not be found for zlib,
      a required dependency when compiling Pillow from source.

and also

Collecting Pillow
  Using cached Pillow-9.2.0.tar.gz (50.0 MB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: Pillow
  Building wheel for Pillow (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Kyuujin
  • 71
  • 1
  • 5
  • The error is not exactly about that Pillow is missing, but about the dependencies of `zlib` (*The headers or library files could not be found for zlib*), which seems to be one of Pillow's dependencies. You need to be able to install zlib first, to install Pillow. – Gino Mempin Sep 04 '22 at 10:44

3 Answers3

6

You need zlib-dev. This installs the headers that you need to compile parts of Pillow.

You will likely come across the same message for jpeg; for this, you need the libjpeg-turbo-dev package.

vpseg
  • 71
  • 5
  • Good point, but I am not sure which distribution and version you are referring to. For instance, Debian wheezy seems to have different packages. – Wtower Sep 29 '22 at 11:46
  • 1
    @Wtower Indeed. These are the package names for much of the debian family. Usually, RPM distros use `-devel` instead of `-dev`. Click the links in my answer; pkgs.org shows you the package name across over 50 different distros, which is why I only put in the names for Debian. – vpseg Sep 30 '22 at 15:15
  • Thanks for clarifying that @vpseg. I hadn’t properly noticed the links. – Wtower Sep 30 '22 at 20:24
1

I was facing the same issue on my mac. For me, after running the following commands, it worked:

  1. brew install zlib
  2. brew install jpeg
  3. export LDFLAGS="-L/usr/local/opt/zlib/lib"
  4. export CPPFLAGS="-I/usr/local/opt/zlib/include"
Soumendra
  • 1,518
  • 3
  • 27
  • 54
  • 1
    My homebrew used a different folder. I needed export `LDFLAGS="-L/opt/homebrew/opt/zlib/lib"` and export `CPPFLAGS="-I/opt/homebrew/opt/zlib/include"`. The relevant folder can be found using `brew --prefix zlib` – Dominik Peters Aug 23 '23 at 13:22
-2

if you are linux user you can do this

pip install pillow

or

sudo apt install python3-pil