How can you programmatically get a Python package's list of dependencies?
The standard setup.py
has these documented, but I can't find an easy way to access it from either Python or the command line.
Ideally, I'm looking for something like:
$ pip install somepackage --only-list-deps
kombu>=3.0.8
billiard>=3.3.0.13
boto>=2.26
or:
>>> import package_deps
>>> package = package_deps.find('somepackage')
>>> print package.dependencies
['kombu>=3.0.8', 'billiard>=3.3.0.13', 'boto>=2.26']
Note, I'm not talking about importing a package and finding all referenced modules. While this might find most of the dependent packages, it wouldn't be able to find the minimum version number required. That's only stored in the setup.py.
In addition to the
pip show [package name]
command, there ispipdeptree
.Just do
then run
and it will show you your dependencies in a tree form, e.g.,
The project is located at https://github.com/naiquevin/pipdeptree, where you will also find usage information.
Alex's answer is good (+1). In python:
should return something like
where twisted is the name of the package, which you can find in the dictionary :
to list them all:
should give you lists like this:
Try to use
show
command inpip
, for example:Update (retrieve deps with specified version):
All of the above solutions are correct but somewhat inefficient. If your using a MAC, the best way would to be use the 'pip list' command.
MacBook-Pro:~ AIMASTER$ pip list
Hope this helps... Boo YA
Try this according to this article in python:
It will show like: