pipdeptree¶
pipdeptree is a command-line utility that displays installed Python packages as a dependency tree. It works for
packages installed globally or inside a virtualenv.
Why use pipdeptree?¶
pip freeze shows all installed packages as a flat list, making it hard to tell which are top-level packages and
which are transitive dependencies. pipdeptree solves this by rendering the full dependency graph as a tree:
$ pip freeze
Flask==0.10.1
itsdangerous==0.24
Jinja2==2.11.2
MarkupSafe==0.22
Werkzeug==0.11.2
$ pipdeptree
Flask==0.10.1
- itsdangerous [required: >=0.21, installed: 0.24]
- Jinja2 [required: >=2.4, installed: 2.11.2]
- MarkupSafe [required: >=0.23, installed: 0.22]
- Werkzeug [required: >=0.7, installed: 0.11.2]
The same relationships, visualized as a graph:
flowchart TD
flask["Flask<br/>0.10.1"] --> itsdangerous["itsdangerous<br/>0.24"]
flask --> jinja2["Jinja2<br/>2.11.2"]
flask --> werkzeug["Werkzeug<br/>0.11.2"]
jinja2 --> markupsafe["MarkupSafe<br/>0.22"]
jinja2 -. "CONFLICT: requires >=0.23" .-> markupsafe
style markupsafe fill:#e74c3c,color:#fff
Beyond visualization, pipdeptree can:
Detect conflicting dependencies – packages required at incompatible versions by different parents.
Find circular dependencies – cycles in the dependency graph.
Reverse lookup – find out why a package is installed (
--reverse --packages <name>).Export to JSON, Mermaid diagrams, or Graphviz graphs for further analysis.