在 macOS 10.15 上安装Pillow
2019-10-17 18:18:18    382    0    0
lijim

最近升级到macOS Catalina 10.15, Python 3.8.0后安装Pillow出现以下错误,费了一番功夫才碰巧解决了,特别记录一下。

 

$ pip install Pillow

Collecting Pillow

  Using cached https://files.pythonhosted.org/packages/87/dc/7597336c48796d4a836007460148b7baf7f278ad42b73d49047eb0e8194c/Pillow-6.2.0.tar.gz

Installing collected packages: Pillow

    Running setup.py install for Pillow ... error

    ...

    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

   ...

 

根据提示安装zlib

$ brew install zlib

Warning: zlib 1.2.11 is already installed and up-to-date

To reinstall 1.2.11, run `brew reinstall zlib`

 

再链接zlib

$ brew link zlib --force

Warning: Refusing to link macOS-provided software: zlib

For compilers to find zlib you may need to set:

  export LDFLAGS="-L/usr/local/opt/zlib/lib"

  export CPPFLAGS="-I/usr/local/opt/zlib/include"


For pkg-config to find zlib you may need to set:

  export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig"

 

根据提示重新安装Pillow

$ export LDFLAGS="-L/usr/local/opt/zlib/lib"

export CPPFLAGS="-I/usr/local/opt/zlib/include"

pip install Pillow 

Collecting Pillow

  Using cached https://files.pythonhosted.org/packages/87/dc/7597336c48796d4a836007460148b7baf7f278ad42b73d49047eb0e8194c/Pillow-6.2.0.tar.gz

Installing collected packages: Pillow

    Running setup.py install for Pillow ... done

Successfully installed Pillow-6.2.0

终于成功了。

 

参考:

https://github.com/python-pillow/Pillow/issues/3438

上一篇: 无

下一篇: 最近用到的几个Docker命令

382 人读过
立即登录, 发表评论.
没有帐号? 立即注册
0 条评论
文档导航