Is there any way to show the dependency trees for pip packages?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Orient Looping
--
Chapters
00:00 Is There Any Way To Show The Dependency Trees For Pip Packages?
00:55 Accepted Answer Score 298
01:30 Answer 2 Score 11
01:52 Answer 3 Score 11
02:22 Answer 4 Score 5
03:36 Answer 5 Score 0
04:22 Thank you
--
Full question
https://stackoverflow.com/questions/1719...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pip #requirementstxt
#avk47
ACCEPTED ANSWER
Score 310
You should take a look at pipdeptree:
$ pip install pipdeptree
$ pipdeptree -fl
Warning!!! Cyclic dependencies found:
------------------------------------------------------------------------
xlwt==0.7.5
ruamel.ext.rtf==0.1.1
xlrd==0.9.3
openpyxl==2.0.4
- jdcal==1.0
pymongo==2.7.1
reportlab==3.1.8
- Pillow==2.5.1
- pip
- setuptools
It doesn't generate a requirements.txt file as you indicated directly. However the source (255 lines of python code) should be relatively easy to modify to your needs, or alternatively you can (as @MERose indicated is in the pipdeptree 0.3 README ) out use:
pipdeptree --freeze --warn silence | grep -P '^[\w0-9\-=.]+' > requirements.txt
The 0.5 version of pipdeptree also allows JSON output with the --json option, that is more easily machine parseble, at the expense of being less readable.
ANSWER 2
Score 13
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.
Install pipdeptree package using pip
pip install pipdeptree
pipdeptree -fl
This package will list all the dependencies of your project.
For more pipdeptree
ANSWER 3
Score 11
Warning: py2 only / abandonware
yolk can display dependencies for packages, provided that they
- were installed via
setuptools came with metadata that includes dependency information
$ yolk -d Theano Theano 0.6.0rc3 scipy>=0.7.2 numpy>=1.5.0
ANSWER 4
Score 6
I realize that many years has passed since this question was asked, but it showed up in my searches so I thought I'd share some knowledge.
The pip-tools package contains a tool called pip-compile that seems to also solve the original poster's problem.
pip-compile takes an input file, which can be setup.py, setup.cfg, pyproject.toml, or requirements.in. The input file is what you write by hand and contains the "direct" dependencies. It may not specify exact dependency versions, but may use version ranges (nor no constraints at all). The tool outputs a new rquirements.txt file with all the indirect dependencies added and also pins down the dependencies to exact versions.
If you run the pip-compile tool again after updating the source file, it will add or remove dependencies from the output file if needed. You can also choose to upgrade a specific dependency by adding a flag.
So while pip-compile does not show you the dependency tree itself, it helps you with collecting all the leafs of the dependency tree (which I assume was what the original poster wanted to do in the end).
Read more here: https://github.com/jazzband/pip-tools/
