首页 > 其他分享 >PIL、Pillow安装使用方法

PIL、Pillow安装使用方法

时间:2023-05-01 11:31:41浏览次数:45  
标签:PIL python Image import 安装 Pillow


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

Pillow的文档:http://pillow.readthedocs.io/en/latest/

Pillow的github:https://github.com/python-pillow/Pillow

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

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


PIL、Pillow安装使用方法_python

0x1. windows安装PIL

PIL安装很麻烦,推荐下载exe直接安装

PIL官网:http://pythonware.com/products/pil/


0x2. windows安装Pillow

pip install Pillow

或者在http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow 下载wheel文件使用pip安装

 

0x3. linux安装python2.7、pip

sudo apt-get install python
sudo apt-get install python-pip

 

0x4. linux安装Pillow

在linux里安装PIL不怎么建议,依赖也多,而且会有各种报错。

kali的python默认已安装了Pillow。

在debian/ubuntu里安装Pillow:

sudo apt-get install python-imaging

或者

sudo pip install -I --no-cache-dir -v Pillow

python-imaging安装后的支持import Image

 

0x5. Pillow wrapper for PIL compatibility

github地址:https://github.com/yinpeng/pillow-pil

其作者是这样介绍:他项目中也使用Pillow替代了PIL,不过PIL和Pillow的import语句不兼容导致本项目代码修改倒还好说,问题是后来使用的依赖PIL的第三方组件不兼容,我们既不想同时安装Pillow和PIL,又不想修改第三方组件的源代码,所以他写了个很简单的Pillow-PIL,使得依赖PIL的第三方组件不用修改源代码就可以使用Pillow了。安装法子如下:

pip install Pillow-PIL

 

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

 

标签:PIL,python,Image,import,安装,Pillow
From: https://blog.51cto.com/u_14523369/6238641

相关文章

  • win10环境Windows环境下MYSQL5.7免安装版下载、配置(win10-x64位32g内存)
    win101-Windows环境下MYSQL5.7免安装版下载、配置(win10-x64位32g内存)  一、MYSQL免安装版下载二、解压安装三、设置登录、修改密码一、MYSQL免安装版下载1、下载链接:https://downloads.mysql.com/archives/community/.2、MySQL5.x版本以上需要收费,所以我选择了一个最新的(m......
  • linux下安装redis
    1.安装gccyuminstall-ygcc-c++2.下载安装包https://download.redis.io/releases/redis-6.2.0.tar.gz3.解压tar-zxvfredis-6.2.0.tar.gz4.编译安装cdredis-6.2.0make##/home/redis为安装目录##makeinstallPREFIX=/home/redis5.拷贝配置文件并授权mkdir-......
  • SQL Server2012安装
    一,安装前准备工作1,安装包  2,关闭防火墙(必须)3,关闭杀毒软件(我没有关闭杀毒软件也安装成功了) 二,安装过程点“setup.exe”   Developer版本,自带密钥    报错:防火墙警告,是因为我安装之前没有关闭防火墙解决:关闭防火墙,点“重新运行”下,就全部运行通过......
  • MariaBD安装配置
    官方地址:https://mariadb.com/docs/server/deploy/topologies/single-node/community-server-10-5/YUM安装:1、下载用到wget工具;yuminstallwget2、下载MariaDBrepo的安装文件;默认下载到当前文件夹wgethttps://r.mariadb.com/downloads/mariad......
  • ESXI 群辉安装注意事项
    系统/磁盘类型Linux系统选择其他4.x或更高版本的Linux(64位),选择其他64位不行,没有sata控制器查找设备使用这个而不要用域内iphttps://finds.synology.com或http://10.10.10.104:5000confirm:disk_format_dialog_input_model_title报错不要使用Safari浏览器!!......
  • openGauss单机+主从集群部署_万能场景安装_搭建_适用所有场景_openGauss3.0.0_openGau
    一、opengauss的背景和行业现状2022年,七大openGauss商业版发布,是基于openGauss3.0推出商业发行版目前海量数据库Vastbase表现最佳,一直是TOP1作者认为之所以海量数据库Vastbase目前无法被同行超越,和各家研发实力和技术背景有关众所周知,opengauss起源于postgresql,在......
  • KaliLinux安装Burpsuite
    注意事项1.注意linux位数安装jdk之前先输出uname-a,看看kalilinux是32位的还是64位,例如此处我的kali是32位的,因此需下载的是32位的jdk2.jdk版本jdk版本最好是oracle的,若使用的是openjdk很可能会出现burpsuite闪退现象安装JDK1.解压jdk将jdk压缩包解压至kali的/opt目录......
  • java基于ssm的房屋租赁管理系统、房屋出租管理系统、租房管理系统,附源码+数据库,免费安
    1、项目介绍java基于ssm的房屋租赁管理系统、房屋出租管理系统、租房管理系统,​系统分为前台用户界面和后台系统管理。项目获取,看这里1.1前台用户界面用户注册、用户登录、用户中心、浏览房源、房源搜索查看房源明细、发布房源、提交合同、新闻公告、留言交流1.2后台系统......
  • Prometheus 监控系统安装
    目录下载启动使用参考Prometheus既是一个时序数据库,又是一个监控系统,更是一套完备的监控生态解决方案。本文简要介绍Prometheus的安装和使用。下载根据系统下载Download版本,并解压tarxvfzprometheus-*.tar.gzcdprometheus-*启动./prometheus--config.file=prometh......
  • Windows11 安装OpenSSH服务器
    windows系统在可选功能中添加OpenSSH服务器,但是一直报错就不知道如何解决,在网上也没有查到有效的解决办法。最好的办法是手动安装OpenSSH服务,方法如下:1.下载OpenSSHGitHub地址:https://github.com/PowerShell/Win32-OpenSSH/releases下载OpenSSH-Win64.zip2.安装OpenSSH-......