22

Is there a tool for analyzing Conda dependencies as we do have in Maven?

ie: In Java projects (maven based) you say mvn dependency:tree and it shows all the dependencies (along with transitive dependencies) in a readable tree format.

I was wondering if we have something in python based project to analyze Conda dependencies.

Any suggestions?

Lovey
  • 880
  • 3
  • 15
  • 31
  • If you are just looking for packages you can use `pip freeze` to list the currently installed packages and their respective versions. Is that along the lines of what you are looking for? – C.Nivs Apr 30 '19 at 00:33
  • I want to see what all dependencies are in my application along with their transitive dependencies. The core idea is to prune unnecessary dependencies. – Lovey Apr 30 '19 at 19:23
  • There is the `conda install/remove --prune package_name` command that walks the tree and prunes unnecessary packages. But I'm not aware of a way to visualize that. – darthbith Apr 30 '19 at 20:01

1 Answers1

24

Check out conda-tree.

Usage (based on the conda-tree webpage):

# version
$ conda-tree --version
conda-tree 0.0.4

# packages that no other package depends on
$ conda-tree leaves
['samtools','bcftools',...]

# dependencies of a specific package
$ conda-tree depends samtools
['curl', 'xz', 'libgcc', 'zlib']

# which packages depend on a specific package
$ conda-tree whoneeds xz
['samtools', 'bcftools', 'htslib', 'python']

# dependency cycles
$ conda-tree cycles
pip -> python -> pip
pip -> wheel -> python -> pip

# query a different conda prefix/env
$ conda-tree -p /conda/envs/trinity leaves
['trinity']

# query by name
$ conda-tree -n trinity leaves
['trinity']

For dependencies installed with pip, check out pipdeptree. It will return a dependency tree of the packages (installed with pip. See the documentation)

try:

pipdeptree

Or if you are looking for the leaves only

pipdeptree --freeze  --warn silence | grep -P '^[\w0-9\-=.]+'

See also this answer.

pareyesv
  • 590
  • 5
  • 11
  • When I run `./conda-tree.py leaves`, I get `bash: ./conda-tree.py: No such file or directory`, so that command obviously doesn't as is. Where is `conda-tree.py` located? – HelloGoodbye Jul 17 '19 at 18:12
  • OK. I just changed the commands. It seems that the README is outdated. Thanks @HelloGoodbye – pareyesv Jul 22 '19 at 13:04
  • 1
    It seems that `conda-tree` fails to list any packages installed with `pip`; at least on my system. – HelloGoodbye Jul 22 '19 at 21:20
  • 1
    @HelloGoodbye [`pipdeptree`](https://github.com/naiquevin/pipdeptree) works for packages installed with `pip` – pareyesv Jul 25 '19 at 21:08
  • 1
    That is correct. Pipdeptree doesnnot work for Conda – Lovey Apr 03 '20 at 06:15
  • @Lovey I just updated the answer. See also https://github.com/naiquevin/pipdeptree#limitations--alternatives – pareyesv Jul 15 '20 at 10:19
  • Thanks, let me check. – Lovey Jul 16 '20 at 20:35
  • is there any tools like `pipdeptree` in the `conda` repo (i couldn't find conda tree in the `conda search`)? – Trevor Boyd Smith Mar 31 '21 at 13:58
  • @trevor-boyd-smith you have to install the packages [conda-tree](https://anaconda.org/conda-forge/conda-tree), [pipdeptree](https://anaconda.org/conda-forge/pipdeptree) from [conda-forge](https://conda-forge.org/). – pareyesv Apr 25 '21 at 12:56
  • `conda install -c conda-forge conda-tree` to install – Jasha Nov 22 '22 at 00:57
  • `conda-tree whoneeds --tree --full` to see deeper-level dependency relationships. Omitting `--tree` results in a list of just the packages that _immediately_ depend on ``, not accounting for transitive dependencies. – Jasha Nov 22 '22 at 01:02