python pil 怎么安装

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python pil 怎么安装相关的知识,希望对你有一定的参考价值。

关于Pillow与PIL

PIL(Python Imaging Library)是Python一个强大方便的图像处理库,名气也比较大。不过只支持到Python 2.7。

PIL官方网站:http://www.pythonware.com/products/pil/

Pillow是PIL的一个派生分支,但如今已经发展成为比PIL本身更具活力的图像处理库。目前最新版本是3.0.0。

Pillow的Github主页:https://github.com/python-pillow/Pillow
Pillow的文档(对应版本v3.0.0):https://pillow.readthedocs.org/en/latest/handbook/index.html
Pillow的文档中文翻译(对应版本v2.4.0):http://pillow-cn.readthedocs.org/en/latest/

Python 3.x 安装Pillow

给Python安装Pillow非常简单,使用pip或easy_install只要一行代码即可。

在命令行使用PIP安装:
pip install Pillow

或在命令行使用easy_install安装:
easy_install Pillow

安装完成后,使用from PIL import Image就引用使用库了。比如:
from PIL import Image
im = Image.open("bride.jpg")
im.rotate(45).show()
参考技术A Mac OSX
brew update
brew install libjpeg libpng
装这两个就够了

Ubuntu 14.0.4
sudo apt-get install libjpeg-dev libpng12-dev libfreetype6-dev libtiff-dev
Linux 上比较惨一些,要多装几个包.

这还不够的, 最好就直接用 Pillow 这个 python 包来取代手工下载 Imaging 这个包吧,直接用以下指令

pip install -I --no-cache-dir -v Pillow
这个指令执行完毕会有一大堆的信息,不用管它,只要找到以下这个就行了:
--------------------------------------------------------------------
PIL SETUP SUMMARY
--------------------------------------------------------------------
version Pillow 3.2.0
platform linux2 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2]
--------------------------------------------------------------------
*** TKINTER support not 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
--------------------------------------------------------------------
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.
参考技术B

命令行窗口键入(假设我下载的PIL文件存放在E盘下,文件名叫Pillow-3.3.1-cp27-cp27m-win_amd64.whl)

pip  install e:\\Pillow-3.3.1-cp27-cp27m-win_amd64.whl

安装完毕,需要检查一下安装是否成功。

本回答被提问者采纳

Python PIL库安装

由于需要使用Python操作图片,想使用sudo pip install PIL引入PIL(Python Imaging Library)库,但是结果如下:

could not find a version that satisfies the requirement PIL.(form versions:)
No matching distribution found for PIL.

这个提示很费解,只能去找度娘了,原来已经用Pillow代替了PIL,在使用方面没有不同,API都是相同的。真是个挨千刀的,提示信息里怎么不告诉我们这些刚学Python的小白呢,还得白忙活半天。既然这样那就老老实实安装Pillow吧。但是又发现Pillow需要依赖multiprocessing,所以必须先安装multiprocessing。命令如下:

sudo pip install multiprocessing

接着再执行如下命令:

sudo pip install Pillow

引入模块要按照下面的方式写(注意大小写)
第一种:from PIL import Image
第二种:from PIL.Image(用这种方式时,下面使用时也得写成PIL.Image.open(‘1.png‘),或者可以在引入时修改下模块名,如from PIL.Image as image)

引入之后就可以正常使用了。



以上是关于python pil 怎么安装的主要内容,如果未能解决你的问题,请参考以下文章

新手小白求助:关于python安装PIL时的问题

python pil 怎么设定图片的dpi

自学Python:解决Python3无法安装PIL三方库的办法

python中pil如何导入?

Python第三方库怎么安装

tesseract 训练字库 python 怎么调用