Is it possible to show the reverse dependencies with pip
?
I want to know which package needs package foo
. And which version of foo
is needed by this 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.
Unfortunately, pip makes no attempt to resolve dependency conflicts. For example, if you install two packages, package A may require a different version of a dependency than package B requires. Pip can install from either Source Distributions (sdist) or Wheel (. whl) files.
Pip does not provide true dependency resolution, but this can be solved by using it in conjunction with a requirements. txt file. Requirements. txt files can be used to make pip resolve dependency conflicts between different packages.
A reverse dependency – meaning another package depends on the existence of your package Note – Use the reverse dependency type only when a package that cannot deliver a depend file relies on your package. An incompatible package – meaning your package is incompatible with the named package.
I found Alexander's answer perfect, except it's hard to copy/paste. Here is the same, ready to paste:
import pip def rdeps(package_name): return [pkg.project_name for pkg in pip.get_installed_distributions() if package_name in [requirement.project_name for requirement in pkg.requires()]] rdeps('some-package-name')
To update the answer to current (2019), when pip.get_installed_distributions()
does not exist anymore, use pkg_resources
(as mentioned in a comments):
import pkg_resources import sys def find_reverse_deps(package_name): return [ pkg.project_name for pkg in pkg_resources.WorkingSet() if package_name in {req.project_name for req in pkg.requires()} ] if __name__ == '__main__': print(find_reverse_deps(sys.argv[1]))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With