Pragmatism in the real world

Cannot find zlib headers on macOS 10.15 Catalina

My new MacBook Pro 16″ comes with Catalina and while setting up Python to develop rst2pdf, I discovered that Pillow wouldn’t install.

    Running setup.py install for pillow ... error
    ERROR: Command errored out with exit status 1:

Looking through the long list of red text I came across:

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

Aha!

The way this was solved on the previous version of macOS (Mojave) was to use the macOS_SDK_headers_for_macOS_10.14.pkg installer to set up symlinks to header files from the old place to the new place.

This doesn’t work on Catalina, so we need to add the correct directory to the CPATH, but putting this in our .zshrc (or .bashrc if you upgraded from Mojave)

export CPATH=`xcrun --show-sdk-path`/usr/include

Restart your terminal and then Pillow along with any other package that requires zlib or other standard headers will now install.

Alternatively, if you’re a little lazy, you can try:

sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/

However, Homebrew or something similar may come along and clobber what you’ve done in the future.

10 thoughts on “Cannot find zlib headers on macOS 10.15 Catalina

  1. this fixed issue for me on catalina (you have xcode tool alread installed):
    sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/

  2. Brilliant, spent 1/2 day trying to get PIP installed on my Mac (catalina 10.15.5). This is what finally worked for me:
    sudo SLUGIFY_USES_TEXT_UNIDECODE=yes CPATH=`xcrun –show-sdk-path`/usr/include pip install -r ~/requirements.txt

Comments are closed.