16

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.

I've tried:

import PIL
print('PIL',PIL.__version__)

And I've got the error:

AttributeError: module 'PIL' has no attribute '__version__'
1
  • This question and answer have nothing specifically to do wtih Mac OS X, it would be nice to simply remove that from the title, it throws people off searching for this question on google. Apr 7, 2018 at 17:39

5 Answers 5

21

Use PIL.__version__ or Image.__version__.

Before Pillow version 6.0.0, its version string could be accessed via the following variable names:

>>> 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):

>>> 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

However, PIL's homepage states

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.

That release is dated "November 15, 2009".

This confirms it's just PIL's last release version.


For future/further digging:

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.

(On my Windows, this is installed to %LocalAppData%\Programs\Python\Python36\Lib\site-packages\PIL\version.py)


**Update**

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, and PILLOW_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.

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.


2021-12 - this answer is still correct:
>>> import PIL
>>> PIL.__version__
'8.4.0'
>>> from PIL import Image
>>> Image.__version__
'8.4.0'
>>> Image.__version__ is PIL.__version__
True
7

To get the version for PIL do

>>> PIL.VERSION
'1.1.7'

Edit:

This gives you only the PIL version not the Pillow version. See this answer for more detail.

3
  • 1
    Thanks! I've found another solution but yours is working fine too! Jun 24, 2017 at 18:47
  • 1
    Note that this only returns the last version string of PIL, which pillow is based on (but they kept the module name).
    – handle
    Apr 8, 2018 at 19:32
  • 1
    To clarify: this does not return the version of Pillow.
    – handle
    Apr 8, 2018 at 19:49
1

Finally I've found a solution:

from PIL import Image 
print('PIL',Image.VERSION)
1
  • 1
    This does not return the Version of Pillow, but the (old) underlying PIL version. It is identical to PIL.VERSION (source).
    – handle
    Apr 8, 2018 at 19:52
1

I tried the above answers, nothing worked for me, but this did (for version 8.0.1:

from PIL import Image
dir(Image)
# AH HAH!  there is an attribute __version__
print(Image.__version__)

8.0.1

0

If you are not importing the entire PIL library but instead have something like this:

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.

1
  • Both of these have been deprecated since 5.2.0 (before you posted this answer).
    – handle
    Jul 9, 2022 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.