发布于 2018-04-09 03:43:47
使用PIL.__version__
。
在Pillow版本6.0.0之前,可以通过以下变量名访问其版本字符串:
>>> PIL.version.__version__
'5.1.0'
>>> PIL.PILLOW_VERSION
'5.1.0'
>>> PIL.__version__
'5.1.0'
>>>
不要与Pillow构建在其上的最后一个PIL版本混淆(因此会挂在上面):
>>> PIL.VERSION
'1.1.7'
在关于来自PIL的分支的文档中没有关于这一点的信息:https://pillow.readthedocs.io/en/5.1.x/about.html#why-a-fork
然而,PIL's homepage声明
状态
当前的免费版本是PIL 1.1.7。此版本支持Python 1.5.2 >及更高版本,包括2.5和2.6。3.X的版本将在稍后发布。
该版本的日期是“2009年11月15日”。
这证实了它只是PIL的最新发布版本。
对于将来/进一步的挖掘:
版本字符串在以下源文件中定义:https://github.com/python-pillow/Pillow/blob/master/src/PIL/version.py
和https://github.com/python-pillow/Pillow/blob/master/src/PIL/__init__.py
,或存储库中的search for all occurences of __version__
。
(在我的Windows上,这是安装在%LocalAppData%\Programs\Python\Python36\Lib\site-packages\PIL\version.py
上的)
更新
https://pillow.readthedocs.io/en/stable/releasenotes/5.2.0.html
5.2.0 API更改弃用
这些版本常量已被弃用。在Pillow 6.0.0中将删除VERSION
,之后将删除PILLOW_VERSION
。
PIL.VERSION
(旧的PIL版本1.1.7) PIL.PILLOW\_VERSION
PIL.Image.VERSION
PIL.Image.PILLOW\_VERSION
请改用PIL.__version__
。
https://pillow.readthedocs.io/en/stable/releasenotes/6.0.0.html
6.0.0向后不兼容的更改
删除了不推荐使用的版本
VERSION
(旧的PIL版本,始终为1.1.7)已被删除。改为使用__version__
。
发布于 2017-06-25 02:45:50
发布于 2020-12-18 14:17:51
我尝试了上面的答案,没有一个对我有效,但这个有效(对于版本8.0.1:
from PIL import Image
dir(Image)
# AH HAH! there is an attribute __version__
print(Image.__version__)
8.0.1
https://stackoverflow.com/questions/44739775
复制相似问题