LoginSignup
0
1

More than 1 year has passed since last update.

Pythonのモジュールとライブラリとパッケージの違い

Posted at

何度も同じことを調べているので覚書として書きます。

モジュールとライブラリとパッケージの関係性

モジュールとは、クラスや関数を用いて実行したい内容を記述したPythonのファイル(.py)のこと。
モジュールをいくつか集めてまとめたものがパッケージ。
ライブラリとは、いくつかのパッケージをまとめて一つのライブラリとしてインストールできるようにしたもの。

また関数、モジュール、パッケージ自体を総称してライブラリと言うこともある(←これがややこしくする原因)。

つまり、関係性は以下の通り。
クラスや関数 < モジュール < ライブラリ < パッケージ

ライブラリは2種類ある

1, 標準ライブラリ

標準ライブラリはPythonに付属している。組み込み関数とそれ以外に分けることができる。
組み込み関数は、以下の通り。

abs(), delattr(), hash(), memoryview(), set(), all(), dict(), help(), min(), setattr(), any(), dir(), hex(), next(), slice(), ascii(), divmod(), id(), object(), sorted(), bin(), enumerate(), input(), oct(), staticmethod(), bool(), eval(), int(), open(), str(), breakpoint(), exec(), isinstance(), ord(), sum(), bytearray(), filter(), issubclass(), pow(), super(), bytes(), float(), iter(), print(), tuple(), callable(), format(), len(), property(), type(), chr(), frozenset(), list(), range(), vars(), classmethod(), getattr(), locals(), repr(), zip(), compile(), globals(), map(), reversed(), __import__(), complex(), hasattr(), max(), round()

上記の組み込み関数以外の標準ライブラリはimport文で読み込む必要がある。
例えばcsv、osなど。

詳細は公式HPへ
https://docs.python.org/ja/3/library/index.html

2, 外部ライブラリ

外部ライブラリを利用する場合はpipを利用してライブラリをインストールする。
インストールしたライブラリは事前にimport文で読み込みが必要。
例えば、NumPy、Matplotlib、Pandasなど。

Pythonの外部ライブラリの一覧は、PYPI(Python Package Index)へ
https://pypi.org/

参考

0
1
0

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