よちよちpython

独習 python/Qpython/Pydroid3/termux/Linux

【pip show <ライブラリ名>】インストール済みライブラリの依存ライブラリを調べる方法【pipdeptree】

インストール済みライブラリの依存関係を調べる方法。

  • pip show <ライブラリ名>



これだけ。
ターミナル上でpipコマンドで行います。
Anacondaを使っている場合、condaコマンドで インストールしたライブラリも同じように出来ます。

実行環境

これを書いている & 動作確認環境



確認した環境

  • Windows10 Home
  • Anaconda (Windowsに直でインストール)
  • Python 3.9



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-byjapanize-matplotlibが載っている理由は、matplotlibの豆腐文字化けをなくし日本語表示するこのライブラリをインストールした為。



その他のツール

pip show <ライブラリ名>以外では、pipdeptreeという外部ライブラリがあるようです。

pipdeptree のインストール方法

$ pip install pipdeptree

# または、condaなら
$ conda install -c conda-forge pipdeptree

参照 Pipdeptree :: Anaconda.org



名前に「tree」と付くように、Linuxのtreeコマンド風にインストール済みPythonライブラリの依存関係を表示してくれるようです(未確認)。

参考



以上。