加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-16 21:04:30 所属栏目:Python 来源:网络整理
导读:今天帮朋友做个python的小工具,发现系统上缺少ptyhon的支持库,返回如下信息 ImportError: No module named PIL 然后就下载安装,因为机器上也没有python的管理工具pip,所以也一并安装 1. 安装pip sudo easy_install pip pip 安装成功就可以直接安装pil或者

今天帮朋友做个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,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切片工具pillow用法示例
  • python+pillow绘制矩阵盖尔圆简单实例
  • python3 pillow生成简单验证码图片的示例
  • Python用Pillow(PIL)进行简单的图像操作方法
  • Python实现更改图片尺寸大小的方法(基于Pillow包)
  • Python基于pillow判断图片完整性的方法
  • Linux上安装Python的PIL和Pillow库处理图片的实例教程
  • Python编程中使用Pillow来处理图像的基础教程
  • Python中pillow知识点学习

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读