PIL、Pillow安装使用方法

博客介绍了Pillow库相关内容,包括在Windows和Linux下安装冲突的解决方法,给出安装和卸载命令;还记录了PIL的拷贝、剪切、缩放及格式转换操作;同时列举常见报错问题,如Windows安装报错、Pillow报KeyError等,并给出解决建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

安装冲突解决方法:windos和linux通用

PIL拷贝,剪切,缩放 格式转换笔记

常见报错问题:


安装冲突解决方法:windos和linux通用

windows下面两个安装命令是都可以:

pip install pillow pip install Pillow

pip uninstall PIL

PIL拷贝,剪切,缩放 格式转换笔记

pil拷贝,剪切,缩放 笔记_AI视觉网奇的博客-优快云博客

 

常见报错问题:

PIL(Python Imaging Library)是Python常用的图像处理库,而Pillow是PIL的一个友好Fork,提供了了广泛的文件格式支持,强大的图像处理能力,主要包括图像储存、图像显示、格式转换以及基本的图像处理操作等。

Pillow的文档:Pillow (PIL Fork) 9.3.0.dev0 documentation

Pillow的github:GitHub - python-pillow/Pillow: The friendly PIL fork (Python Imaging Library)

-----------------------------------------------------------------

0x0. Pillow的注意事项

Pillow and PIL cannot co-exist in the same environment. Before installing Pillow, please uninstall PIL.
Pillow >= 1.0 no longer supports “import Image”. Please use “from PIL import Image” instead.
Pillow >= 2.1.0 no longer supports “import _imaging”. Please use “from PIL.Image import core as _imaging” instead.

Pillow < 2.0.0 supports Python versions 2.4, 2.5, 2.6, 2.7.
Pillow >= 2.0.0 < 4.0.0 supports Python versions 2.6, 2.7, 3.2, 3.3, 3.4, 3.5
Pillow >= 4.0.0 supports Python versions 2.7, 3.3, 3.4, 3.5, 3.6

0x6. PIL一些报错

ImportError:The _imagingft C module is not installed

这个是在windows里安装PIL所报错,建议直接exe安装。

PIL.Image.open() IOError: cannot identify image file

首先检查图片是不是正确的,如果各种检查过还是有问题建议重装PIL

0x7. Pillow报KeyError问题

python
>>> import Image
>>> Image.init()
1
>>> Image.SAVE.keys()
['PCX', 'HDF5', 'EPS', 'MSP', 'XBM', 'WEBP', 'BUFR', 'PPM', 'BMP', 'TGA', 'ICO', 'TIFF', 'JPEG', 'SPIDER', 'GIF', 'GRIB', 'IM', 'FITS', 'PDF', 'WMF', 'MPO', 'PALM', 'JPEG2000', 'PNG']

如果Image.SAVE.keys()输出为空,则说明没有找到save format key,在生成图片时就会报KeyError, 此时就需要把import Image改成from PIL import Image

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值