Pillow: Install zlib on OS X?

Created on 2 Oct 2015  Â·  15Comments  Â·  Source: python-pillow/Pillow

The installation instructions are missing how to install zlib:
https://pillow.readthedocs.org/en/3.0.x/installation.html#os-x-installation

[hugo:~/github/Pillow] master(98)+* ± brew install libtiff libjpeg webp little-cms2
Warning: jpeg-8d already installed
Warning: You are using OS X 10.11.
We do not provide support for this pre-release version.
You may encounter build failures or other breakage.
Error: libtiff-4.0.3 already installed
To install this version, first `brew unlink libtiff'
Error: webp-0.4.2_1 already installed
To install this version, first `brew unlink webp'
Error: little-cms2-2.6 already installed
To install this version, first `brew unlink little-cms2'
[hugo:~/github/Pillow] master(98)+* 1 ± python setup.py develop
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-8.2.1-py2.7.egg/setuptools/dist.py:289: UserWarning: The version specified requires normalization, consider using '3.1.0.dev0' instead of '3.1.0.dev'.
running develop
running egg_info
writing Pillow.egg-info/PKG-INFO
writing top-level names to Pillow.egg-info/top_level.txt
writing dependency_links to Pillow.egg-info/dependency_links.txt
writing pbr to Pillow.egg-info/pbr.json
reading manifest file 'Pillow.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'Pillow.egg-info/SOURCES.txt'
running build_ext
Traceback (most recent call last):
  File "setup.py", line 767, in <module>
    zip_safe=not debug_build(),
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "build/bdist.macosx-10.9-x86_64/egg/setuptools/command/develop.py", line 32, in run
  File "build/bdist.macosx-10.9-x86_64/egg/setuptools/command/develop.py", line 117, in install_for_development
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build_ext.py", line 337, in run
    self.build_extensions()
  File "setup.py", line 515, in build_extensions
    % (f, f))
ValueError: --enable-zlib requested but zlib not found, aborting.
macOS

Most helpful comment

@aclark4life is correct. xcode-select --install command will install toolchain that also contain libz used during Pillow compilation.

All 15 comments

Pretty sure we rely on OS X and/or XCode's zlib e.g.

/usr/lib/libz.1.1.3.dylib
/usr/lib/libz.1.2.5.dylib
/usr/lib/libz.1.dylib
/usr/lib/libz.dylib

@aclark4life is correct. xcode-select --install command will install toolchain that also contain libz used during Pillow compilation.

Thanks, xcode-select --install did it (followed by sudo xcodebuild -license because I had a new version).


We distribute wheels for OS X, so normally this isn't needed, but should we document this somehow in case someone wants to build from source?

@hugovk Maybe. At the very least, we should list XCode as a requirement (if we don't already) because without that you can't compile (i.e. with gcc) let alone rely on libz being present.

Here is the current note in the docs that XCode is needed to compile from source - https://github.com/python-pillow/Pillow/blob/master/docs/installation.rst#user-content-os-x-installation

I hope my wife forgives me for installing the dev tools on her machine as a test...

Ok, I've reorg'd the installation docs, including the xcode-select bit. Also added the bit about pip --no-cache-dir and tried to draw a distinction between installing and building from source.

I hope my wife forgives me for installing the dev tools on her machine as a test...

This time yes. You need to worry when you reinstall the OS to get a blank slate for next time...

With the merge of the PR, is this issue resolved?

Looking at http://pillow.readthedocs.org/en/latest/index.html the reorg looks good, but I'm not sure we mention anywhere that zlib is included with XCode (I could be wrong).

Good enough for me:

Building on OS X

Xcode is required to compile portions of Pillow.

https://pillow.readthedocs.org/en/latest/installation.html#building-on-os-x

I've closed the issue. Thanks!

Update to Mac OS X catalina seems to have broken the path again. The package file is no longer available to install. Please look into it. Can't install pillow.
ValueError: --enable-zlib requested but zlib not found, aborting.

EDIT:
Packages are in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include. Just made a env variable CFLAGS pointing to that location to include the headers

@nautatva This issue is closed … if you have trouble on Catalina, please open a new issue. (Although, FYI "works for me":

Screen Shot 2019-11-22 at 2 30 40 PM
)

@nautatva Actually I do get this with Python 2.7 on Catalina:

(esrd) ➜  esrd git:(master) ✗ bin/buildout 
Installing plone.
Getting distribution for 'Pillow==6.2.0'.
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
  warnings.warn(msg)
warning: no files found matching '*.c'
warning: no files found matching '*.h'
warning: no files found matching '*.sh'
warning: no previously-included files found matching '.appveyor.yml'
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.codecov.yml'
warning: no previously-included files found matching '.editorconfig'
warning: no previously-included files found matching '.readthedocs.yml'
warning: no previously-included files found matching 'azure-pipelines.yml'
warning: no previously-included files matching '.git*' found anywhere in distribution
warning: no previously-included files matching '*.pyc' found anywhere in distribution
warning: no previously-included files matching '*.so' found anywhere in distribution
no previously-included directories found matching '.azure-pipelines'
no previously-included directories found matching '.travis'


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

Please see the install instructions at:
   https://pillow.readthedocs.io/en/latest/installation.html

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 332, in _handle_workers
    debug('worker handler exiting')
TypeError: 'NoneType' object is not callable

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 370, in _handle_tasks
    debug('task handler got sentinel')
TypeError: 'NoneType' object is not callable
Exception 
TypeError: TypeError("'NoneType' object does not support item deletion",) in <Finalize object, dead> ignored
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/alexclark/Developer/esrd/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1924, in main
    with_ei_usage(lambda:
  File "/Users/alexclark/Developer/esrd/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1911, in with_ei_usage
    return f()
  File "/Users/alexclark/Developer/esrd/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1928, in <lambda>
    distclass=DistributionWithoutHelpCommands, **kw
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/Users/alexclark/Developer/esrd/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 374, in run
    self.easy_install(spec, not self.no_deps)
  File "/Users/alexclark/Developer/esrd/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 590, in easy_install
    return self.install_item(None, spec, tmpdir, deps, True)
  File "/Users/alexclark/Developer/esrd/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 639, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/Users/alexclark/Developer/esrd/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 825, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/Users/alexclark/Developer/esrd/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1031, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/Users/alexclark/Developer/esrd/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1016, in run_setup
    run_setup(setup_script, args)
  File "/Users/alexclark/Developer/esrd/lib/python2.7/site-packages/setuptools/sandbox.py", line 69, in run_setup
    lambda: execfile(
  File "/Users/alexclark/Developer/esrd/lib/python2.7/site-packages/setuptools/sandbox.py", line 120, in run
    return func()
  File "/Users/alexclark/Developer/esrd/lib/python2.7/site-packages/setuptools/sandbox.py", line 71, in <lambda>
    {'__file__':setup_script, '__name__':'__main__'}
  File "setup.py", line 902, in <module>

__main__.RequiredDependencyException: 

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

Please see the install instructions at:
   https://pillow.readthedocs.io/en/latest/installation.html


An error occurred when trying to install Pillow 6.2.0. Look above this message for any errors that were output by easy_install.
While:
  Installing plone.
  Getting distribution for 'Pillow==6.2.0'.
Error: Couldn't install: Pillow 6.2.0


@nautatva At which point the fix described here resolved the issue 😄 https://github.com/python-pillow/Pillow/issues/3438#issuecomment-543812237

export CPATH=`xcrun --show-sdk-path`/usr/include
Was this page helpful?
0 / 5 - 0 ratings

Related issues

etc0de picture etc0de  Â·  4Comments

readyready15728 picture readyready15728  Â·  4Comments

anonymous530 picture anonymous530  Â·  3Comments

hxzhao527 picture hxzhao527  Â·  4Comments

FlowerCode picture FlowerCode  Â·  4Comments