Zlib error when installing Pillow on Mac
Asked Answered
R

4

19

I've been trying to install the module Pillow on my Mac (running a fresh install of El Capitan and python 3.5) for some time now. Using pip3 install Pillow, I get an error saying that zlib is not found, which then causes the install to abort. I've installed Xcode, so theoretically zlib is already installed, and when I installed it with brew pip still didn't work (so I uninstalled). It works fine until it gets to here:

writing Pillow.egg-info/PKG-INFO
writing dependency_links to Pillow.egg-info/dependency_links.txt
writing top-level names to Pillow.egg-info/top_level.txt
warning: manifest_maker: standard file '-c' not found

reading manifest file 'Pillow.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'Pillow.egg-info/SOURCES.txt'
copying PIL/OleFileIO-README.md -> build/lib.macosx-10.6-intel-3.5/PIL
running build_ext
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/tmp/pip-build-1yfcb2pj/Pillow/setup.py", line 767, in <module>
    zip_safe=not debug_build(),
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/setuptools-18.3.2-py3.5.egg/setuptools/command/install.py", line 61, in run
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/command/install.py", line 539, in run
    self.run_command('build')
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/command/build.py", line 135, in run
    self.run_command(cmd_name)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/command/build_ext.py", line 338, in run
    self.build_extensions()
  File "/private/tmp/pip-build-1yfcb2pj/Pillow/setup.py", line 515, in build_extensions
    % (f, f))
ValueError: --enable-zlib requested but zlib not found, aborting.

----------------------------------------
Command      "/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-1yfcb2pj/Pillow/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-oxzqi2c0-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-build-1yfcb2pj/Pillow

Any idea why it errors and how I can fix it?

Richel answered 2/10, 2015 at 14:25 Comment(0)
T
23

Running

$ xcode-select --install

seems to have solved the problem for me.

Thill answered 7/10, 2015 at 22:21 Comment(3)
helped me solve an el capitan problem too - but why, what is xcode-select?Headachy
xcode-select manages the active developer directory for Xcode and BSD tools. --install opens a user interface dialog to request automatic installation of the command line developer tools.Minsk
solved issue on El Capitan. This type of Q&A saves hours for people. ThanksHaymes
S
7

For Mojave (10.14), you may also need to run the following command:

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
Selfpity answered 22/1, 2019 at 17:52 Comment(0)
W
6

This is what worked for me on an M1 Mac for Python 2.7.18 on macOS v12.0.1 (Monterey):

LDFLAGS="-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
CFLAGS="-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include" pip install Pillow

Successfully installed Pillow-6.2.2
Warrigal answered 8/12, 2021 at 11:3 Comment(3)
This worked for me on this ancient python 2.7 project, thank you!Deicer
Worked for me on Monterey and Python 3.9.13Lafollette
Worked for me on Sonoma, thank you!Reformism
S
0

Here's what worked for me on MacOS Sonoma with Homebrew, Python 3.12 and Poetry.

Install zlib and libjpeg through Homebrew:

brew install zlib libjpeg

Set the CFLAGS environment variable and run the install command:

CFLAGS="-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"
poetry install

As pointed out in another answer, you might need the LDFLAGS but when I ran the above it was not necessary.

Snipe answered 28/6 at 11:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.