Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see all packages that depend on a certain package with PIP?

I would like to see a list of packages that depend on a certain package with PIP. That is, given django, I would like to see django-cms, django-filer, because I have these packages installed and they all have django as dependency.

like image 313
linkyndy Avatar asked Dec 17 '13 13:12

linkyndy


People also ask

How do I check the dependencies of a pip package?

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 check Python package dependencies?

Find package dependencies with Pipdeptree If you want to find all (including nested) dependencies: use pipdeptree, which is a command-line tool with many options for listing and visualizing dependencies. Runnin the pipdeptree command in your terminal will print all of your packages' dependencies.

How do I check my PyPI dependencies?

To just get the dependency-check CLI tool installed into your home, independent of any project, call python3 -m pip install --user dependency-check as usual, see releases for an overview of available versions.

Does pip install all dependencies?

Pip relies on package authors to stipulate the dependencies for their code in order to successfully download and install the package plus all required dependencies from the Python Package Index (PyPI).


2 Answers

Update (2021):

Since pip version 10 you can do:

pkg=httplib2 pip show $pkg | grep ^Required-by 

or for bash

pkg=httplib2 grep ^Required-by <(pip show $pkg) 

so you could create an alias like:

alias pyreq='pip show $pkg | grep ^Required-by' 

and querying by:

pkg=httplib2 pyreq 

which should give (for ubuntu):

Required-by: lazr.restfulclient, launchpadlib 

Original:

Quite straightforward:

pip show <insert_package_name_here>| grep ^Requires 

Or the other way around: (sorry i got it wrong!)

for NAME in $(pip freeze | cut -d= -f1); do REQ=$(pip show $NAME| grep Requires); if [[ "$REQ" =~ "$REQUIRES" ]]; then echo $REQ;echo "Package: $NAME"; echo "---" ; fi;  done 

before that set your search-string with:

REQUIRES=django 

essentially you have to go through the whole list and query for every single one. That may take some time.


Edit: Also it does only work on installed packages, I don't see pip providing dependencies on not installed packages.

like image 166
Don Question Avatar answered Oct 13 '22 00:10

Don Question


I know there's already an accepted answer here, but really, it seems to me that what you want is to use pipdeptree:

pip install pipdeptree pipdeptree --help  pipdeptree -r -p django 
like image 20
Viktor Haag Avatar answered Oct 13 '22 02:10

Viktor Haag