There’s an interesting library available, that lists s. We’ll cover just the basics here, but I encourage you to explore it in more more depth on your own.
The johnnydep
library
You can simply install it with pip install johnnydep.
Then, if you want to get the list of dependencies of latest version of i.e Django library, you can call it with:
johnnydep Django
and it will output:
2022-10-29 19:55:46 [info ] init johnnydist [johnnydep.lib] dist=Django parent=None 2022-10-29 19:55:50 [info ] init johnnydist [johnnydep.lib] dist=asgiref<4,>=3.5.2 parent=Django 2022-10-29 19:55:51 [info ] init johnnydist [johnnydep.lib] dist=backports.zoneinfo parent=Django 2022-10-29 19:55:52 [info ] init johnnydist [johnnydep.lib] dist=sqlparse>=0.2.2 parent=Django name summary ---------------------- ------------------------------------------------------------------------------------------------ Django A high-level Python web framework that encourages rapid development and clean, pragmatic design. ├── asgiref<4,>=3.5.2 ASGI specs, helper code, and adapters ├── backports.zoneinfo Backport of the standard library zoneinfo module └── sqlparse>=0.2.2 A non-validating SQL parser.
Or you can specify the library’s version as well:
johnnydep Django==4.0.3
and it will list the dependencies for that version:
2022-10-29 19:54:51 [info ] init johnnydist [johnnydep.lib] dist=Django==4.0.3 parent=None 2022-10-29 19:54:56 [info ] init johnnydist [johnnydep.lib] dist=asgiref<4,>=3.4.1 parent=Django==4.0.3 2022-10-29 19:54:57 [info ] init johnnydist [johnnydep.lib] dist=backports.zoneinfo parent=Django==4.0.3 2022-10-29 19:54:58 [info ] init johnnydist [johnnydep.lib] dist=sqlparse>=0.2.2 parent=Django==4.0.3 name summary ---------------------- ------------------------------------------------------------------------------------------------ Django==4.0.3 A high-level Python web framework that encourages rapid development and clean, pragmatic design. ├── asgiref<4,>=3.4.1 ASGI specs, helper code, and adapters ├── backports.zoneinfo Backport of the standard library zoneinfo module └── sqlparse>=0.2.2 A non-validating SQL parser.
List dependencies of all libraries in your project
Let’s first activate the virtualenv or your project:
cd your/project/forlder/ source <venv_name>/bin/activate
List dependencies of installed version of each library
Ok. Now, if you want to list the libraries of your entire project, you can call:
pip freeze | xargs -n1 johnnydep
where pip freeze
lists all installed libraries with their versions (1 library per line) and the -n1
parameter of xargs
command ensures that it will feed 1 line at a time to the johnnydep
library. This will list the dependencies of all libraries in you project, for the versions that you use.
List dependencies of the latest version of each library
You can also list all the dependencies of the latest versions of all of the libraries from your project, by calling:
pip freeze | awk -F "==" '{print $1}' | xargs -n1 johnnydep
The awk -F "==" '{print $1}'
will split the e.g. Django==4.0.3
into Django
and 4.0.3
and will pass only the first value to the johnnydep
library.