首页 > 解决方案 > What is conda shell activation?

问题描述

Anaconda Installing in silent mode says

The installer will not prompt you for anything, including setup of your shell to activate conda. To add this activation in your current shell session:

eval "$(command conda 'shell.bash' 'hook' 2> /dev/null)"

What does this line actually do and what files (eg. update bashrc or bash_profile, etc) are affected?

After having done this, what will happen when I open a bash shell or start a new login?

If there is a detailed documentation, please suggest.

标签: anaconda

解决方案


TLDR;Conda shell 激活是定义一些有助于激活和停用 Conda 环境的 shell 函数的过程,以及一些可选功能,例如更新 PS1 以显示活动环境。


在 Conda v4.4 中,对 Conda 管理环境隔离的方式进行了重大改革。其中一部分是使用带有or之conda()类的参数的 shell 函数来管理环境的激活,而不是拥有用户以前必须使用的脚本。activateinstallactivatesource activate

OP 中的特定命令生成 bash 代码来定义conda()函数、它需要的一些辅助函数和环境变量,然后在您当前的 shell 中评估此代码。这不是一个固定脚本的原因是,Conda 在这里所做的工作是使用conda入口点(即 Python 代码)动态生成的,并考虑了~/.condarc.

您只需运行即可完全检查此代码而无需对其进行评估

conda shell.bash hook

这会将代码输出为字符串。每个人都会看到的共同元素是conda()函数及其辅助元素(例如,以 开头__conda_)。其他方面取决于配置。例如,如果auto_activate_base为 true(默认值),则最后conda activate base会发出 a。


推荐阅读