There is a quick way to know if a package is installed in Anaconda

Viewed 942

Installing a package in Anaconda takes at least 15 seconds, if the package is already installed the resolving environment still takes time:

time /opt/Anaconda3-2019.10/bin/conda install --override-channels --quiet -y plotly-orca
Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... done

# All requested packages already installed.


real    0m15.067s
user    0m13.533s
sys     0m0.401s

But checking if the package (regardless of the version) is installed takes only 2 seconds:

time /opt/Anaconda3-2019.10/bin/conda list --quiet plotly-orca
# packages in environment at /opt/Anaconda3-2019.10:
#
# Name                    Version                   Build  Channel
plotly-orca               1.3.1                         1    plotly

real    0m2.303s
user    0m2.227s
sys     0m0.064s

I'm aware I could do a little bit of Shell scripting around this but there is a better way to install a package ONLY if is not present already?

Does conda has an API (similar to pip) that you could use to check for this?

I looked through all the options on the with conda install --help , found nothing I could use (--satisfied-skip-solve seems to help for already installed packages but does it break new installations?).

Thanks!

1 Answers

As Merv mentions in a comment:

Yeah, -S|--satisfied-skip-solve addresses this. You can do dry runs (-d) to test its behavior for new packages - works fine for me. Seems like you already answered your own question. I would note you may want to also include a --update-specs flag: this tells Conda that you explicitly want the package(s) in the environment into the future. This addresses the situation of packages that installed only as dependencies and would normally be removed were the depending package removed.

Related