繁体   English   中英

在 Mac 上安装 Pillow 时出现 Zlib 错误

[英]Zlib error when installing Pillow on Mac

我一直在尝试在我的 Mac 上安装 Pillow 模块(运行全新安装的 El Capitan 和 python 3.5)有一段时间了。 使用 pip3 install Pillow 时,我收到一条错误消息,指出未找到 zlib,然后导致安装中止。 我已经安装了 Xcode,所以理论上 zlib 已经安装了,当我用 brew pip 安装它时仍然没有工作(所以我卸载了)。 它工作正常,直到它到达这里:

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

知道为什么会出错以及如何修复它吗?

运行

$ xcode-select --install

似乎已经为我解决了这个问题。

对于Mojave(10.14),您可能还需要运行以下命令:

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

这就是在 M1 mac for python 2.7.18 on Monterey 12.0.1 上对我有用的方法:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM