有一种快速的方法可以知道 Anaconda 中是否安装了一个包

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

在Anaconda中安装一个包至少需要15秒,如果包已经安装解析环境仍然需要时间:

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

但是检查包(无论版本)是否安装只需要2秒:

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

我知道我可以围绕这个做一些 Shell 脚本但是有更好的方法来安装一个包,如果不存在的话?

conda 是否有一个 API(类似于 pip)可以用来检查这个?

我查看了 conda install --help 上的所有选项,没有发现我可以使用的东西(--satisfied-skip-solve 似乎对已安装的软件包有帮助,但它会破坏新安装吗?)。

谢谢!

作为

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.