如何获得 Python Pillow (PIL) 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44739775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get Python Pillow (PIL) version?
提问by Claude COULOMBE
I would like to get the PIL(Python Imaging Library) version installed on a Mac OS X computer. I've previously installed Pillow, a more friendly fork of PIL.
我想在 Mac OS X 计算机上安装PIL(Python 成像库)版本。我以前安装过Pillow,这是一个更友好的 PIL 分支。
I've tried:
我试过了:
import PIL
print('PIL',PIL.__version__)
And I've got the error:
我有错误:
AttributeError: module 'PIL' has no attribute '__version__'
回答by handle
Use PIL.__version__
.
使用PIL.__version__
.
Before Pillowversion 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 homepagestates
但是,PIL 的主页指出
Status
The current free version is PIL 1.1.7. This release supports Python 1.5.2 >and newer, including 2.5 and 2.6. A version for 3.X will be released later.
状态
当前的免费版本是 PIL 1.1.7。此版本支持 Python 1.5.2 > 及更新版本,包括 2.5 和 2.6。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/__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
)
Update更新
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
These version constants have been deprecated.
VERSION
will be removed in Pillow 6.0.0, andPILLOW_VERSION
will be removed after that.`PIL.VERSION` (old PIL version 1.1.7) `PIL.PILLOW_VERSION` `PIL.Image.VERSION` `PIL.Image.PILLOW_VERSION`
Use
PIL.__version__
instead.
5.2.0 API 更改弃用
这些版本常量已被弃用。
VERSION
将在 Pillow 6.0.0PILLOW_VERSION
中移除,之后将被移除。`PIL.VERSION` (old PIL version 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
https://pillow.readthedocs.io/en/stable/releasenotes/6.0.0.html
6.0.0 Backwards Incompatible Changes
Removed deprecated VERSION
VERSION
(the old PIL version, always 1.1.7) has been removed. Use__version__
instead.
6.0.0 向后不兼容的变化
删除了不推荐使用的版本
VERSION
(旧的 PIL 版本,总是 1.1.7)已被删除。使用__version__
来代替。
回答by Shreyash S Sarnayak
回答by Claude COULOMBE
Finally I've found a solution:
最后我找到了一个解决方案:
from PIL import Image
print('PIL',Image.VERSION)