【pip show <ライブラリ名>】インストール済みライブラリの依存ライブラリを調べる方法【pipdeptree】
インストール済みライブラリの依存関係を調べる方法。
pip show <ライブラリ名>
これだけ。
ターミナル上でpipコマンドで行います。
Anacondaを使っている場合、condaコマンドで
インストールしたライブラリも同じように出来ます。
実行環境
これを書いている & 動作確認環境
確認した環境
Jupyter Notebookでこの投稿を書いているので、セルにマジックコマンド%pip
で実行します。
- 試しに pandas の依存ライブラリを調べる
%pip show pandas
Name: pandas
Version: 1.3.5
Summary: Powerful data structures for data analysis, time series, and statistics
Home-page: https://pandas.pydata.org
Author: The Pandas Development Team
Author-email: pandas-dev@python.org
License: BSD-3-Clause
Location: /data/data/com.termux/files/usr/lib/python3.10/site-packages
Requires: numpy, python-dateutil, pytz
Required-by:
Note: you may need to restart the kernel to use updated packages.
依存ライブラリは下の方にある requires : 以下に
書いてある。
- 「requires :」 Pandasが必要とする依存ライブラリ
(インストール時に自動的にインストールされるライブラリ) - 「required-by :」 Pandasに依存しているライブラリ
もうひとつ、matplotlibの依存ライブラリを調べてみる。
%pip show matplotlib
Name: matplotlib
Version: 3.5.1
Summary: Python plotting package
Home-page: https://matplotlib.org
Author: John D. Hunter, Michael Droettboom
Author-email: matplotlib-users@python.org
License: PSF
Location: /data/data/com.termux/files/usr/lib/python3.10/site-packages
Requires: cycler, fonttools, kiwisolver, numpy, packaging, pillow, pyparsing, python-dateutil
Required-by: japanize-matplotlib
Note: you may need to restart the kernel to use updated packages.
Requires
cycler, fonttools, kiwisolver, numpy, packaging, pillow, pyparsing, python-dateutil
Required-by
japanize-matplotlib
Termux
でNumpyやPillowはpip install
一発ですんなりインストール出来なかったりします。いきなりPandasをインストールすると、依存ライブラリのNumpyやPillowの自動インストールで躓き、Pandasのインストールは失敗したりする。
required-by
にjapanize-matplotlib
が載っている理由は、matplotlibの豆腐文字化けをなくし日本語表示するこのライブラリをインストールした為。
その他のツール
pip show <ライブラリ名>
以外では、pipdeptree
という外部ライブラリがあるようです。
pipdeptree のインストール方法
$ pip install pipdeptree # または、condaなら $ conda install -c conda-forge pipdeptree
名前に「tree」と付くように、Linuxのtreeコマンド風にインストール済みPythonライブラリの依存関係を表示してくれるようです(未確認)。
参考
以上。