Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python package dependency tree

Tags:

I would like to analyze the dependency tree of Python packages. How can I obtain this data?

Things I already know

  1. setup.py sometimes contains a requires field that lists package dependencies
  2. PyPi is an online repository of Python packages
  3. PyPi has an API

Things that I don't know

  1. Very few projects (around 10%) on PyPi explicitly list dependencies in the requires field but pip/easy_install still manage to download the correct packages. What am I missing? For example the popular library for statistical computing, pandas, doesn't list requires but still manages to install numpy, pytz, etc.... Is there a better way to automatically collect the full list of dependencies?
  2. Is there a pre-existing database somewhere? Am I repeating existing work?
  3. Do similar, easily accessible, databases exist for other languages with distribution systems (R, Clojure, etc...?)
like image 639
MRocklin Avatar asked Mar 29 '13 17:03

MRocklin


People also ask

How do I get the dependencies tree of Python package?

One easy way of doing so is to use the pipdeptree utility. The pipdeptree works on the command line and shows the installed python packages in the form of a dependency tree.

How do you check the dependency of a package in Python?

Pip Check Command – Check Python Dependencies After Installation. Because pip doesn't currently address dependency issues on installation, the pip check command option can be used to verify that dependencies have been installed properly in your project. For example: $ pip check No broken requirements found.

How do I see the dependency tree in pip?

You can do it by installing pipdeptree package. Open command prompt in your project folder. If you are using any virtual environment, then switch to that virtual environment. This package will list all the dependencies of your project.

What are Python package dependencies?

Dependencies are all of the software components required by your project in order for it to work as intended and avoid runtime errors. You can count on PyPI (the Python Package Index) to provide packages that can help you get started on everything from data manipulation to machine learning to web development, and more.


1 Answers

You should be looking at the install_requires field instead, see New and changed setup keywords.

requires is deemed too vague a field to rely on for dependency installation. In addition, there are setup_requires and test_requires fields for dependencies required for setup.py and for running tests.

Certainly, the dependency graph has been analyzed before; from this blog article by Olivier Girardot comes this fantastic image:

PyPI dependencies
The image is linked to the interactive version of the graph.

like image 172
Martijn Pieters Avatar answered Oct 07 '22 23:10

Martijn Pieters