Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to show the dependency trees for pip packages?

People also ask

How do I get the dependencies tree of Python package?

One easy way of doing so is to use the pipdeptree utility. The pipdeptree works on the command line and shows the installed python packages in the form of a dependency tree.

Does pip freeze show dependencies?

Since pip freeze shows all dependencies as a flat list, finding out which are the top level packages and which packages do they depend on requires some effort. It's also tedious to resolve conflicting dependencies that could have been installed because older version of pip didn't have true dependency resolution [1].

How do you see all pip installed packages?

To do so, we can use the pip list -o or pip list --outdated command, which returns a list of packages with the version currently installed and the latest available. On the other hand, to list out all the packages that are up to date, we can use the pip list -u or pip list --uptodate command.


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.


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
    

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

enter image description here