美文网首页python自学
Python: Pillow vs. PIL (Python I

Python: Pillow vs. PIL (Python I

作者: 正在学习的Yuki | 来源:发表于2019-06-21 14:21 被阅读3次

Import Pillow 时出现 ModuleNotFoundError错误

Error 错误:

安装Pillow:pip install Pillow
并导入:

from Pillow import Image

运行出现错误:

ModuleNotFoundError: No module named 'Pillow'

Solution 解决方案:

import应改为:

from PIL import Image

Reason 原因:

PIL与Pillow:

PIL (Python Imaging Library) 是Python中的一个图像处理库,但于2009年停止发布更新。
Pillow是PIL的一个派生分支 (PIL fork)。但为了保持向后兼容性,沿用旧模块名PIL。

Example 示例:

from PIL import Image, ImageFilter
#Read image
im = Image.open( 'image.jpg' )
#Display image
im.show()

#Applying a filter to the image
im_sharp = im.filter( ImageFilter.SHARPEN )
#Saving the filtered image to a new file
im_sharp.save( 'image_sharpened.jpg', 'JPEG' )

#Splitting the image into its respective bands, i.e. Red, Green,
#and Blue for RGB
r,g,b = im_sharp.split()

#Viewing EXIF data embedded in image
exif_data = im._getexif()
exif_data

Pillow tutorial:https://pillow.readthedocs.io/en/3.0.x/handbook/tutorial.html
参考来源:https://docs.python-guide.org/scenarios/imaging/

相关文章

网友评论

    本文标题:Python: Pillow vs. PIL (Python I

    本文链接:https://www.haomeiwen.com/subject/fwyyqctx.html