LoginSignup
8
3

More than 3 years have passed since last update.

Python インストール名とインポート名が違う。よくあることか?(install pillow,import PIL)

Last updated at Posted at 2019-07-09

目的

たぶん、ライブラリとかパッケージとかモジュールとかという意味でなく、
なぜか、
インストール名とインポート名が違うものがあったので、メモ。
沢山あるのかもしれない。
全く、pythonを使いこんでないので、最初に出会った例に過ぎないかもしれないが、、、

インストールやimportがグダグダになると、出端をくじかれるので、、、、

pillow、PIL

前提として、Pillow is the friendly PIL forkです。
 ※friendly fork:フレンドリーな分身

↓ まず、pillowをimportしてみる。
 入れてないので、エラーでしょう。これは、そうでしょう。

C:\_tmp>
C:\_tmp>python
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 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>
ModuleNotFoundError: No module named 'pillow'

↓ 次に、PILをimportしてみる。
 入れてないので、エラーでしょう。これは、そうでしょう。

>>> import PIL
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PIL'
>>> exit()

↓ 次に、pillowをインストールしてみる。
 問題なくインストールできる。

C:\_tmp>python -m pip install pillow
Collecting pillow
  Using cached https://files.pythonhosted.org/packages/ae/96/6f83deebfcd20a5d4ad35e4e989814a16559d8715741457e670aae1a5a09/Pillow-6.1.0-cp37-cp37m-win_amd64.whl
Installing collected packages: pillow
Successfully installed pillow-6.1.0

↓ 次に、PILをインストールしてみる。
インストールできない。

C:\_tmp>python -m pip install PIL
Collecting PIL
  ERROR: Could not find a version that satisfies the requirement PIL (from versions: none)
ERROR: No matching distribution found for PIL

↓ 次に、pillowをimportしてみる。
importできない。先ほど、インストールしたのに!!

C:\_tmp>python
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 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>
ModuleNotFoundError: No module named 'pillow'

↓ 次に、PILをimportしてみる。
importできる。先ほど、インストール成功したのは、pillowなのに!!

>>> import PIL
>>>

追記

「Pillow is the friendly PIL fork」だから、pillowだけど、名前はPILなんでしょう。

C:\_tmp>python -m pydoc pillow

と呼びかけても、

No Python documentation found for 'pillow'.
Use help() to get the interactive help utility.
Use help(str) for help on the str class.


↑知りませんと出る。

C:\_tmp>python -m pydoc PIL

PILとして問い合わせると、

Help on package PIL:

NAME
    PIL - Pillow (Fork of the Python Imaging Library)

DESCRIPTION
    Pillow is the friendly PIL fork by Alex Clark and Contributors.
        https://github.com/python-pillow/Pillow/

    Pillow is forked from PIL 1.1.7.

    PIL is the Python Imaging Library by Fredrik Lundh and Contributors.
    Copyright (c) 1999 by Secret Labs AB.

と反応する。
まあ、「PIL」というディレクトリに格納されているので、そうなるんでしょうけど。。。

まとめ

単に、インストールはpillowで、importはPILで宜しくということだと思うのですが、
原則からずれてませんかね?
「Pillow is the friendly PIL fork」だとしても、、、、
ちょっと、納得感がありません。

「Pillow is the friendly PIL fork」だから、こんな感じなんでしょう。
類例が沢山あるかは、よくわかっていません。

関連(本人)

pythonをストレスなく使う!(generatorに詳しくなる。since1975らしい。)
pythonをストレスなく使う!(Pythonでは、すべてがオブジェクトとして実装されている)
pythonをストレスなく使う!(Pylintに寄り添う)
pythonをストレスなく使う!(ExpressionとStatement)
英語と日本語、両方使ってPythonを丁寧に学ぶ。

今後

コメントなどあれば、お願いします。:candy:
勉強します、、、、

8
3
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
3