在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常用内置函数总结
Feb 08 Python
Python常用时间操作总结【取得当前时间、时间函数、应用等】
May 11 Python
2018年Python值得关注的开源库、工具和开发者(总结篇)
Jan 04 Python
python2.7 json 转换日期的处理的示例
Mar 07 Python
Django进阶之CSRF的解决
Aug 01 Python
python3判断url链接是否为404的方法
Aug 10 Python
选择python进行数据分析的理由和优势
Jun 25 Python
新手入门Python编程的8个实用建议
Jul 12 Python
opencv实现简单人脸识别
Feb 19 Python
浅谈python中统计计数的几种方法和Counter详解
Nov 07 Python
Python-openpyxl表格读取写入的案例详解
Nov 02 Python
python计算列表元素与乘积详情
Aug 05 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
强制PHP命令行脚本单进程运行的方法
2014/04/15 PHP
PHP大批量插入数据库的3种方法和速度对比
2014/07/08 PHP
PHP清除字符串中所有无用标签的方法
2014/12/01 PHP
深入讲解PHP的Yii框架中的属性(Property)
2016/03/18 PHP
PHP 访问数据库配置通用方法(json)
2018/05/20 PHP
细品javascript 寻址,闭包,对象模型和相关问题
2009/04/27 Javascript
Jquery实现无刷新DropDownList联动实现代码
2010/03/08 Javascript
jQuery自定义事件的简单实现代码
2014/01/27 Javascript
jQuery中slideUp 和 slideDown 的点击事件
2015/02/26 Javascript
js实现的早期滑动门菜单效果代码
2015/08/27 Javascript
js插件Jcrop自定义截取图片功能
2016/10/14 Javascript
前端常见跨域解决方案(全)
2017/09/19 Javascript
简单实现jQuery弹窗效果
2017/10/30 jQuery
Vue.js 的移动端组件库mint-ui实现无限滚动加载更多的方法
2017/12/23 Javascript
vux-scroller实现移动端上拉加载功能过程解析
2019/10/08 Javascript
Vue的Options用法说明
2020/08/14 Javascript
python基础教程之元组操作使用详解
2014/03/25 Python
Centos5.x下升级python到python2.7版本教程
2015/02/14 Python
利用Python读取文件的四种不同方法比对
2017/05/18 Python
python距离测量的方法
2018/03/06 Python
Python秒算24点实现及原理详解
2019/07/29 Python
python破解bilibili滑动验证码登录功能
2019/09/11 Python
浅析python内置模块collections
2019/11/15 Python
wxPython实现列表增删改查功能
2019/11/19 Python
pytorch中的transforms模块实例详解
2019/12/31 Python
pip安装提示Twisted错误问题(Python3.6.4安装Twisted错误)
2020/05/09 Python
HTML5实现一个能够移动的小坦克示例代码
2013/09/02 HTML / CSS
为智能设备设计个性化保护套网站:caseable
2017/01/05 全球购物
UNIX文件名称有什么规定
2013/03/25 面试题
应届生污水处理求职信
2013/11/06 职场文书
工厂总经理岗位职责
2014/02/07 职场文书
关于运动会的广播稿(10篇)
2014/09/12 职场文书
2015年全国助残日活动方案
2015/05/04 职场文书
2015年会计人员工作总结
2015/05/22 职场文书
mysql自增长id用完了该怎么办
2022/02/12 MySQL
CSS中理解层叠性及权重如何分配
2022/12/24 HTML / CSS