Dependency query scheme for Python libraries

Dependency query scheme for Python libraries

In Python development, a large number of third-party libraries are sometimes used. However, there may be dependencies between these libraries, and we don't necessarily know what other libraries each library depends on. What if we need to know the dependencies between these libraries? Several schemes for querying dependencies are introduced below.

Solution 1: Use the pip list command

pip is one of the most commonly used package management tools in Python, it provides many functions, one of which is to list all currently installed packages. You can view the installed Python packages and their version information through the pip list command. In this way, you can know which packages are installed in the current environment, and then you can view other packages they depend on according to the official websites or documents of these packages.

The command is as follows:

pip list

Example output:

Package     Version
----------- -------
numpy       1.20.3
pandas      1.2.4
requests    2.25.1

Solution 2: Use the pipdeptree library

pipdeptree is an extension package of the Python package management tool pip, which can list all packages installed in the current environment and their dependencies. After installing pipdeptree, enter the following command in the terminal:

pipdeptree

Example output:

requests==2.25.1
  - certifi [required: >=2017.4.17, installed: 2020.12.5]
  - charset-normalizer [required: &g

おすすめ

転載: blog.csdn.net/update7/article/details/131028027