macOS Pillow Build

Mac Pillow

Environment:macOS Mojave
Version:10.14.2
Time:2019.03.01

PIL是python的一个图形库,而最新的一个版本是2009年为1.1.7更新的,虽然这么久远了,但是官方还未说明PIL项目被抛弃。而Pillow是fork PIL项目的,Pillow的作者的原意也是为了促进以及支持PIL的积极开发。

macOS 默认自带python2.7的版本,而我的项目是基于python3进行的,所以我装了一个python3,版本是3.7.2的,这里要做的是导下Pillow项目,然后修改了一些代码,然后替换掉系统的PIL。

Note

Pillow支持的python版本

Python2.42.52.62.73.23.33.43.53.63.7
Pillow < 2.0.0YesYesYesYes
Pillow 2.x - 3.xYesYesYesYesYesYes
Pillow 4.xYesYesYesYesYes
Pillow 5.0.x - 5.1.xYesYesYesYes
Pillow >= 5.2.0YesYesYesYesYes

注:PIL和Pillow在相同的环境下会冲突,所以在安装Pillow之前,请先卸载PIL。

预备工作

首先安装python3

其次在GitHub上面导下Pillow项目,在本地进行修改。

git clone https://github.com/python-pillow/Pillow.git MyPillow

然后卸载掉自己电脑上面的PIL(python3使用pip3)

pip3 uninstall PIL

安装Pillow需要用到Xcode的命令行工具,所以需要先执行

xcode-select --install

执行命令行工具之前可能还要接受许可:

sudo xcodebuild -license

你还需要通过Homebrew安装一些Pillow需要用到的依赖库:

brew install libtiff libjpeg webp little-cms2
正式工作

安装本地Pillow项目。进入MyPillow目录,并执行安装命令,

pip3 install .

或者通过在未压缩的项目目录下执行安装:

python3 setup.py install

好了,现在你的电脑就已经成功装上Pillow了

问题

我这里会出现一个问题,就是执行安装的时候会出现zlib模块缺少,报错如下:

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

Traceback (most recent call last):
  File "setup.py", line 803, in <module>
    zip_safe=not (debug_build() or PLATFORM_MINGW), )
  File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", line 143, in setup
    return distutils.core.setup(**attrs)
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python3.7/site-packages/setuptools/command/install.py", line 67, in run
    self.do_egg_install()
  File "/usr/local/lib/python3.7/site-packages/setuptools/command/install.py", line 109, in do_egg_install
    self.run_command('bdist_egg')
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python3.7/site-packages/setuptools/command/bdist_egg.py", line 172, in run
    cmd = self.call_command('install_lib', warn_dir=0)
  File "/usr/local/lib/python3.7/site-packages/setuptools/command/bdist_egg.py", line 158, in call_command
    self.run_command(cmdname)
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python3.7/site-packages/setuptools/command/install_lib.py", line 11, in run
    self.build()
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/command/install_lib.py", line 107, in build
    self.run_command('build_ext')
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/command/build_ext.py", line 339, in run
    self.build_extensions()
  File "setup.py", line 590, in build_extensions
    raise RequiredDependencyException(f)
__main__.RequiredDependencyException: zlib

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "setup.py", line 815, in <module>
    raise RequiredDependencyException(msg)
__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

在全世界Google搜索了几遍之后,尝试了N多次方法之后,还是云里雾里的。在不懈的搜索中,尝试了一下某个帖子的方法,结果还真解决了,想哭。帖子地址:https://github.com/pyenv/pyenv/issues/1219

只要执行以下命令,然后重新安装就成功了。

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

笔记,终。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Title: BSD Hack Author: Ajay Kumar Tiwari Length: 410 pages Edition: 1 Language: English Publication Date: 2015-03-22 ISBN-10: B00V3DWD80 In the world of Unix operating systems, the various BSDs come with a long heritage of high-quality software and well-designed solutions, making them a favorite OS of a wide range of users. Among budget-minded users who adopted BSD early on to developers of some of today's largest Internet sites, the popularity of BSD systems continues to grow. If you use the BSD operating system, then you know that the secret of its success is not just in its price tag: practical, reliable, extraordinarily stable and flexible, BSD also offers plenty of fertile ground for creative, time-saving tweaks and tricks, and yes, even the chance to have some fun."Fun?" you ask. Perhaps "fun" wasn't covered in the manual that taught you to install BSD and administer it effectively. But BSD Hacks, the latest in O'Reilly's popular Hacks series, offers a unique set of practical tips, tricks, tools--and even fun--for administrators and power users of BSD systems.BSD Hacks takes a creative approach to saving time and getting more done, with fewer resources. You'll take advantage of the tools and concepts that make the world's top Unix users more productive. Rather than spending hours with a dry technical document learning what switches go with a command, you'll learn concrete, practical uses for that command.The book begins with hacks to customize the user environment. You'll learn how to be more productive in the command line, timesaving tips for setting user-defaults, how to automate long commands, and save long sessions for later review. Other hacks in the book are grouped in the following areas: Customizing the User Environment Dealing with Files and Filesystems The Boot and Login Environments Backing Up Networking Hacks Securing the System Going Beyond the Basics Keeping Up-to-Date Grokking BSD If you want more than your average BSD user--you want to explore and experiment, unearth shortcuts, create useful tools, and come up with fun things to try on your own--BSD Hacks is a must-have. This book will turn regular users into power users and system administrators into super system administrators.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值