Getting all the nested dependancies for a Conda (Anaconda) Python Package
Finding out what additional packages are installed (and where they come from) when using conda.
--
Setup
Installation of conda-tree
We begin by installing the conda-tree
package. This allows us to browse the dependancies of our environment.
conda install -c conda-forge conda-tree
#or (faster)
mamba install conda-tree
Testing out conda-tree
To check that our installation works, we can see which packages in our current environment are not depended on by any others (these are called leaves). This can be useful in determining what we can delete, without breaking the environment.
$$> conda tree leaves
cmor
conda-tree
ipykernel
gfortran_osx-64
In this example I am looking at the an environment created to run the Climate Model Output Rewriter (CMOR).
Viewing all dependancies of a package
Now we have a working environment, I wish to locate the dependancies of the cmor
package in the environment above.
I begin by running conda-tree
with the depends
argument.
$$> conda tree depends cmor
hdf5
json-c
libgfortran
libgfortran5
libnetcdf
libuuid
netcdf4
numpy
openblas
python
python_abi
six
udunits2
This should match the information of the setup.py
file in the package.
Exploring nested dependancies
I am however intrested in which additional dependancies may be installed. For instance I saw that during the installation a number of aws
packages were added, and I want to know where these come from. To do this I can view the complete dependancy tree by appending the -t
flag to the previous command.
conda tree depends -t cmor
This produces the complete list of dependancies used by conda
, and allows us to locate the culprit above as libnetcdf
.
I am now able to reconsider which packages I wish to install and possibly replace them with a lighter weight alternative — if possible.
Note: the conda-tree package only works for conda packages. For pip installations we may wish to look at
pipdeptree
instead.