Python3、PIL是Pillow的别名吗?

Python 3, is PIL an alias for Pillow?

Python 3.5 on Windows 7 64 位。

我很困惑——如果安装 Pillow,那么必须使用被取代/卸载的图形库的名称 PIL作为它的别名?

根据枕头安装说明 (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." 好的:

D:\Python35>pip uninstall PIL

Cannot uninstall requirement PIL, not installed

下一个:

D:\Python35>pip install Pillow

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

所以现在:

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'

好吧,如果没有 Pillow(或 pillow),我们试试:

import PIL

没有错误,即使 pip 告诉我 PIL 没有安装。下一篇:

dir(PIL)

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

嗯,Ala PIL 与 Pillow 的命名似乎矛盾?

PIL.PILLOW_VERSION

'3.4.1'

3.4.1 是截至该日期的最新版本的 Pillow (https://pypi.python.org/pypi/Pillow)

我很困惑——需要使用 PIL 作为 Pillow 的明显别名似乎是错误的。然而,根据上述情况,似乎有必要这样做?

pillow 库是 PIL 库的继承者。它仍然使用 pil 包名称作为替代品。

  • 安装 Pillow
  • import pil

pip包名和python/import包名不必相同。由于 pillow 旨在替换 PIL,它使用相同的 import 名称以实现兼容性。