Search code examples
pythonpython-imaging-libraryjpegzlib

Command error when installing Pillow v7.0.0 and python 3.8.2


I am trying to install Pillow (dependancy on a work project) and I keep getting an error I can't seem to resolve. I am not a python developer, so these errors are tricky for me to parse.

ERROR: Command errored out with exit status 1:
command: /<path-to-project>/venv/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/gg/djb6q6054pxf6rzpjg516k9c0000gn/T/pip-install-pvhuaqam/pillow/setup.py'"'"'; __file__='"'"'/private/var/folders/gg/djb6q6054pxf6rzpjg516k9c0000gn/T/pip-install-pvhuaqam/pillow/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/gg/djb6q6054pxf6rzpjg516k9c0000gn/T/pip-record-ytuo39f0/install-record.txt --single-version-externally-managed --compile --install-headers /<path-to-project>/venv/include/site/python3.8/Pillow
cwd: /private/var/folders/gg/djb6q6054pxf6rzpjg516k9c0000gn/T/pip-install-pvhuaqam/pillow/
The headers or library files could not be found for zlib, a required dependency when compiling Pillow from source.

I have tried installing Pillow via the requirements.txt file in the project (v7.0.0) and also the prior version (v6.2.2) by typing pip install Pillow==6.2.2. They both error with the same message.

I am on using python 3.8.2 installed on macOS 11.0.1.

I have had no troubles installing all of the other dependancies in the project. Is there anything else I should try? I don't believe I can upgrade the package to a newer version as it was causing issues in our project.


Solution

  • I was able to fix this first error by adding the following to my zshrc file.

    export LDFLAGS="-L/usr/local/opt/zlib/lib"
    export CPPFLAGS="-I/usr/local/opt/zlib/include"
    export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig"
    

    However, it would then fail on:

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

    Which I fixed by running brew install jpeg.