Home pipdeptree views Python Package Dependencies (English)
Post
Cancel

pipdeptree views Python Package Dependencies (English)

Package Dependencies

When developing Python programs, we usually only focus on running the code smoothly and ensuring functionality. However, when packaging with pyinstaller, you might notice that the executable size is much larger than expected. This is because of the complex dependencies between packages, and all dependent packages are included during the packaging process.

At this point, we can use pipdeptree to view the dependencies between packages.

Introduction to pipdeptree

pipdeptree is a tool for displaying the dependency tree of Python packages. It helps you understand the relationships between the packages you have installed, identify potential dependency conflicts, and view the dependency tree for each package. This is very useful for managing and debugging Python environments.

Key Features

  1. Displays Dependency Tree: Shows all installed Python packages and their dependencies, allowing you to see the direct and indirect dependencies of each package clearly.
  2. Detects Dependency Conflicts: Reports and detects dependency conflicts, such as different packages requiring different versions of the same dependency.
  3. Supports Various Output Formats: You can choose different output formats, such as text, JSON, or YAML, to meet different needs.

Install pipdeptree with the following command:

1
pip install pipdeptree

Usage

The usage is very simple. Use the following command to list all dependencies

1
pipdeptree

Desktop View

1
pipdeptree --packages matplotlib

Desktop View

You can even specify a single package and output its dependencies in JSON format:

1
pipdeptree --json --packages <package-name> > dependencies.json

However, outputting in JSON format might not make the package dependencies easy to read. In the next article, we will introduce how to visualize the JSON output as a directed graph.

☝ツ☝

This post is licensed under CC BY 4.0 by the author.

👈 ツ 👍