[英]How to get Python Pillow (PIL) version?
I would like to get the PIL (Python Imaging Library) version installed on a Mac OS X computer.我想在 Mac OS X 计算机上安装PIL (Python 成像库)版本。 I've previously installed Pillow , a more friendly fork of PIL.
我以前安装过Pillow ,这是一个更友好的 PIL 分支。
I've tried:我试过:
import PIL
print('PIL',PIL.__version__)
And I've got the error:我有错误:
AttributeError: module 'PIL' has no attribute '__version__'
Use PIL.__version__
.使用
PIL.__version__
。
Before Pillow version 6.0.0, its version string could be accessed via the following variable names:在Pillow版本 6.0.0 之前,可以通过以下变量名访问其版本字符串:
>>> PIL.version.__version__
'5.1.0'
>>> PIL.PILLOW_VERSION
'5.1.0'
>>> PIL.__version__
'5.1.0'
>>>
Not to be confused with the last PIL version that Pillow is built on (and thus hangs on to):不要与 Pillow 构建的最后一个 PIL 版本混淆(并因此挂起):
>>> PIL.VERSION
'1.1.7'
There was no information on this in the documentation regarding the fork from PIL: https://pillow.readthedocs.io/en/5.1.x/about.html#why-a-fork关于 PIL 的 fork 的文档中没有关于此的信息: https : //pillow.readthedocs.io/en/5.1.x/about.html#why-a-fork
However, PIL's homepage states但是, PIL 的主页指出
Status
状态
The current free version is PIL 1.1.7.当前的免费版本是 PIL 1.1.7。 This release supports Python 1.5.2 >and newer, including 2.5 and 2.6.
此版本支持 Python 1.5.2 > 及更新版本,包括 2.5 和 2.6。 A version for 3.X will be released later.
3.X 的版本将在稍后发布。
That release is dated "November 15, 2009".该版本的发布日期为“2009 年 11 月 15 日”。
This confirms it's just PIL's last release version.这证实它只是 PIL 的最后一个发布版本。
The version string is defined in these source files: https://github.com/python-pillow/Pillow/blob/master/src/PIL/version.py
and https://github.com/python-pillow/Pillow/blob/master/src/PIL/__init__.py
, or search for all occurences of __version__
in the repository.版本字符串在这些源文件中定义:
https://github.com/python-pillow/Pillow/blob/master/src/PIL/version.py
: https://github.com/python-pillow/Pillow/blob/master/src/PIL/version.py
和https://github.com/python-pillow/Pillow/blob/master/src/PIL/__init__.py
,或搜索出现的所有__version__
在库中。
(On my Windows, this is installed to %LocalAppData%\\Programs\\Python\\Python36\\Lib\\site-packages\\PIL\\version.py
) (在我的 Windows 上,它安装到
%LocalAppData%\\Programs\\Python\\Python36\\Lib\\site-packages\\PIL\\version.py
)
https://pillow.readthedocs.io/en/stable/releasenotes/5.2.0.html https://pillow.readthedocs.io/en/stable/releasenotes/5.2.0.html
5.2.0 API Changes Deprecations
5.2.0 API 更改弃用
These version constants have been deprecated.
这些版本常量已被弃用。
VERSION
will be removed in Pillow 6.0.0, andPILLOW_VERSION
will be removed after that.VERSION
将在枕头6.0.0被删除,PILLOW_VERSION
会之后被删除。`PIL.VERSION` (old PIL version 1.1.7) `PIL.PILLOW_VERSION` `PIL.Image.VERSION` `PIL.Image.PILLOW_VERSION`
Use
PIL.__version__
instead.改用
PIL.__version__
。
https://pillow.readthedocs.io/en/stable/releasenotes/6.0.0.html https://pillow.readthedocs.io/en/stable/releasenotes/6.0.0.html
6.0.0 Backwards Incompatible Changes
6.0.0 向后不兼容的变化
Removed deprecated VERSION
删除了不推荐使用的版本
VERSION
(the old PIL version, always 1.1.7) has been removed.VERSION
(旧的 PIL 版本,始终为 1.1.7)已被删除。 Use__version__
instead.改用
__version__
。
I tried the above answers, nothing worked for me, but this did (for version 8.0.1:我尝试了上面的答案,对我没有任何作用,但这确实有效(对于 8.0.1 版:
from PIL import Image
dir(Image)
# AH HAH! there is an attribute __version__
print(Image.__version__)
8.0.1 8.0.1
Finally I've found a solution:最后我找到了一个解决方案:
from PIL import Image
print('PIL',Image.VERSION)
If you are not importing the entire PIL
library but instead have something like this:如果您不导入整个
PIL
库,而是导入如下内容:
from PIL import Image, ImageTk, ImageDraw, ImageFont
Then this works:然后这有效:
print('Image.VERSION', Image.VERSION)
print('Image.PILLOW_VERSION', Image.PILLOW_VERSION)
Results:结果:
Image.VERSION 1.1.7
Image.PILLOW_VERSION 3.1.2
Note: Ubuntu 16.04.6 LTS uses older version of Pillow that was tested back in 2016. It appears the Ubuntu Folks (Canonical) don't like to upgrade python versions after testing.注意: Ubuntu 16.04.6 LTS 使用的是 2016 年测试过的旧版本 Pillow。看起来 Ubuntu Folks(Canonical)在测试后不喜欢升级 python 版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.