在Mac OS系统上安装Python的Pillow库的教程


Posted in Python onNovember 20, 2015

今天帮朋友做个python的小工具,发现系统上缺少ptyhon的支持库,返回如下信息

ImportError: No module named PIL 
然后就下载安装,因为机器上也没有python的管理工具pip,所以也一并安装
1. 安装pip

sudo easy_install pip

pip 安装成功就可以直接安装pil或者pillow

2. 通过命令pip install pil

pip install Pil
Downloading/unpacking Pil 
 Could not find any downloads that satisfy the requirement Pil 
 Some externally hosted files were ignored (use --allow-external Pil to allow). 
Cleaning up... 
No distributions at all found for Pil 
Storing debug log for failure in /Users/macbook/Library/Logs/pip.log

3. 所以就安装pillow

pip install --use-wheel Pillow
Downloading/unpacking Pillow 
 Downloading Pillow-2.4.0.zip (6.5MB): 5.0MB downloaded 
Cleaning up...

弄了会别的回来发现还没有下载完,这叫一个慢呀,于是放弃
4. Git

通过git下载源码地址https://github.com/python-imaging/Pillow

git clone https://github.com/python-imaging/Pillow.git

然后开始编译安装

4.1

python setup.py build_ext -i

编译完之后会提示运行测试例子,并且发现JPEG support not available

-------------------------------------------------------------------- 
version   Pillow 2.4.0 
platform   darwin 2.7.5 (default, Aug 25 2013, 00:04:04) 
       [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] 
-------------------------------------------------------------------- 
--- TKINTER support available 
*** JPEG support not available 
*** OPENJPEG (JPEG2000) support not available 
--- ZLIB (PNG/ZIP) support available 
*** LIBTIFF support not available 
--- FREETYPE2 support available 
*** LITTLECMS2 support not available 
*** WEBP support not available 
*** WEBPMUX support not available 
-------------------------------------------------------------------- 
To add a missing option, make sure you have the required 
library, and set the corresponding ROOT variable in the 
setup.py script. 
 
To check the build, run the selftest.py script.

4.2 因为JPEG support not available,运行python selftest.py报告错误

1 tests of 57 failed. 

于是只好卸载pillow

可以通过pip命令来卸载

pip uninstall pillow 
sudo pip uninstall pillow
Password: 
Uninstalling Pillow: 
 /Library/Python/2.7/site-packages/Pillow-2.4.0-py2.7-macosx-10.9-intel.egg 
 /usr/local/bin/pilconvert.py 
 /usr/local/bin/pildriver.py 
 /usr/local/bin/pilfile.py 
 /usr/local/bin/pilfont.py 
 /usr/local/bin/pilprint.py 
Proceed (y/n)? y  
  Successfully uninstalled Pillow 

成功之后需要安装libjpeg的支持

brew install libjpeg

安装成功之后重新编译pillow

-------------------------------------------------------------------- 
version   Pillow 2.4.0 
platform   darwin 2.7.5 (default, Aug 25 2013, 00:04:04) 
       [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] 
-------------------------------------------------------------------- 
--- TKINTER support available 
--- JPEG support available 
*** OPENJPEG (JPEG2000) support not available 
--- ZLIB (PNG/ZIP) support available 
*** LIBTIFF support not available 
--- FREETYPE2 support available 
*** LITTLECMS2 support not available 
*** WEBP support not available 
*** WEBPMUX support not available 
-------------------------------------------------------------------- 
python selftest.py  

-------------------------------------------------------------------- 
Pillow 2.4.0 TEST SUMMARY  
-------------------------------------------------------------------- 
Python modules loaded from /Users/macbook/yyang/app-devel-source/python/Pillow/PIL 
Binary modules loaded from /Users/macbook/yyang/app-devel-source/python/Pillow/PIL 
-------------------------------------------------------------------- 
--- PIL CORE support ok 
--- TKINTER support ok 
--- JPEG support ok 
*** JPEG 2000 support not installed 
--- ZLIB (PNG/ZIP) support ok 
*** LIBTIFF support not installed 
--- FREETYPE2 support ok 
*** LITTLECMS2 support not installed 
*** WEBP support not installed 
-------------------------------------------------------------------- 
Running selftest: 
--- 57 tests passed.

最后执行安装

sudo python setup.py install
Python 相关文章推荐
Python类的多重继承问题深入分析
Nov 09 Python
python通过pil模块将raw图片转换成png图片的方法
Mar 16 Python
python目录与文件名操作例子
Aug 28 Python
Python进阶篇之字典操作总结
Nov 16 Python
Python处理命令行参数模块optpars用法实例分析
May 31 Python
python散点图实例之随机漫步
Aug 27 Python
Python函数参数匹配模型通用规则keyword-only参数详解
Jun 10 Python
使用NumPy读取MNIST数据的实现代码示例
Nov 20 Python
Python递归求出列表(包括列表中的子列表)的最大值实例
Feb 27 Python
Python实现初始化不同的变量类型为空值
Jun 02 Python
python利用tkinter实现图片格式转换的示例
Sep 28 Python
Python+Matplotlib图像上指定坐标的位置添加文本标签与注释
Apr 11 Python
详解Python编程中time模块的使用
Nov 20 #Python
Windows上配置Emacs来开发Python及用Python扩展Emacs
Nov 20 #Python
将Emacs打造成强大的Python代码编辑工具
Nov 20 #Python
Python聚类算法之DBSACN实例分析
Nov 20 #Python
Python聚类算法之凝聚层次聚类实例分析
Nov 20 #Python
Python聚类算法之基本K均值实例详解
Nov 20 #Python
Python实现将xml导入至excel
Nov 20 #Python
You might like
Amazon Prime Video平台《无限住人 -IMMORTAL-》2020年开始TV放送!
2020/03/06 日漫
一步一步学习PHP(7) php 字符串相关应用
2010/03/05 PHP
用PHP编写和读取XML的几种方式
2013/01/12 PHP
2个自定义的PHP in_array 函数,解决大量数据判断in_array的效率问题
2014/04/08 PHP
PHP has encountered a Stack overflow问题解决方法
2014/11/03 PHP
Yii框架上传图片用法总结
2016/03/28 PHP
php 使用curl模拟登录人人(校内)网的简单实例
2016/06/06 PHP
老生常谈PHP数组函数array_merge(必看篇)
2017/05/25 PHP
JQuery 将元素显示在屏幕的中央的代码
2010/02/27 Javascript
jquery 可拖拽的窗体控件实现代码
2010/03/21 Javascript
详解JS去重及字符串奇数位小写转大写
2016/12/29 Javascript
canvas绘制万花筒效果(代码分享)
2017/01/20 Javascript
深入理解ES7的async/await的用法
2017/09/09 Javascript
深入理解Vue nextTick 机制
2018/04/28 Javascript
vue下载二进制流图片操作
2020/10/26 Javascript
Python正规则表达式学习指南
2016/08/02 Python
python将每个单词按空格分开并保存到文件中
2018/03/19 Python
Java与Python两大幸存者谁更胜一筹呢
2018/04/12 Python
解决python3 安装完Pycurl在import pycurl时报错的问题
2018/10/15 Python
对python中的six.moves模块的下载函数urlretrieve详解
2018/12/19 Python
解决python 执行sql语句时所传参数含有单引号的问题
2020/06/06 Python
详解canvas在圆弧周围绘制文本的两种写法
2018/05/22 HTML / CSS
美国全球旅游运营商:Pacific Holidays
2018/06/18 全球购物
德国运动营养和健身网上商店:Myprotein.de
2018/07/18 全球购物
瑞士首家网上药店折扣店:McDrogerie
2020/12/22 全球购物
农村婚礼证婚词
2014/01/08 职场文书
运动会领导邀请函
2014/01/10 职场文书
酒店总经理岗位职责
2014/03/17 职场文书
新闻传媒系求职信范文
2014/04/19 职场文书
巾帼标兵事迹材料
2014/12/26 职场文书
英语专业毕业论文答辩开场白
2015/05/27 职场文书
投诉信回复范文
2015/07/03 职场文书
毕业典礼致辞
2015/07/29 职场文书
学前班教学反思
2016/02/24 职场文书
解读MySQL的客户端和服务端协议
2021/05/10 MySQL
Java Socket实现Redis客户端的详细说明
2021/05/26 Redis