Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3, is PIL an alias for Pillow?

Python 3.5 on Windows 7 64-bit.

I'm confused -- IF one installs Pillow, THEN must one use the name of the superseded / uninstalled graphics library PIL as an alias for it?

Per the Pillow intallation instructions (http://pillow.readthedocs.io/en/3.3.x/installation.html), "Pillow and PIL cannot co-exist in the same environment. Before installing Pillow, please uninstall PIL." Okay:

D:\Python35>pip uninstall PIL

Cannot uninstall requirement PIL, not installed

Next:

D:\Python35>pip install Pillow

Requirement already satisfied (use --upgrade to upgrade): Pillow in d:\python35\lib\site-package

So now:

D:\Python35>python

Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

import Pillow

Traceback (most recent call last):

File "stdin", line 1, in module

ImportError: No module named 'Pillow'

Okay, so if there's no Pillow (or pillow), let's try:

import PIL

No error even though pip told me PIL wasn't installed. Next:

dir(PIL)

['PILLOW_VERSION', 'VERSION', 'builtins', 'cached', 'doc', 'file', 'loader'

Hmm, seemingly contradictory naming ala PIL versus Pillow?

PIL.PILLOW_VERSION

'3.4.1'

3.4.1 being as of this date the latest version of Pillow (https://pypi.python.org/pypi/Pillow)

I'm very confused -- the need to use PIL as an apparent alias for Pillow seems wrong. Yet per the above it seems to be necessary to do that?

like image 532
RBV Avatar asked Oct 11 '16 19:10

RBV


1 Answers

The pillow library is the successor to the PIL library. It still uses the pil package name to serve as a drop-in replacement.

  • install Pillow
  • import pil

The pip package name and python/import package name do not have to be the same. Since pillow is meant to replace PIL, it uses the same import name for compatibility.

like image 132
MisterMiyagi Avatar answered Dec 08 '22 05:12

MisterMiyagi