Cannot find zlib headers on macOS 10.15 Catalina
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.
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.