Import Pillow 时出现 ModuleNotFoundError错误
错误:
安装Pillow:pip install Pillow
并导入:
from Pillow import Image
运行出现错误:
ModuleNotFoundError: No module named 'Pillow'
解决方案:
import应改为:
from PIL import Image
原因:
PIL与Pillow:
PIL (Python Imaging Library) 是Python中的一个图像处理库,但于2009年停止发布更新。
Pillow是PIL的一个派生分支 (PIL fork)。但为了保持向后兼容性,沿用旧模块名PIL。
示例:
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
Reference: https://docs.python-guide.org/scenarios/imaging/