您的 shell 尚未正确配置为使用 'conda activate'

Your shell has not been properly configured to use 'conda activate'

我运行在持续集成中执行以下命令(不是在本地机器上):

conda env create -f python/env/foo.yml && conda init bash && conda activate foo

但是,我收到以下错误:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.


Error: Process completed with exit code 1.

既然是CI,我又无法在CI中打开一个新的shell,如何才能达到同样的效果,才能使用conda activate?

conda init 命令用于将代码添加到 shell 资源文件,为交互式 shell 会话提供功能(如 conda activate)。由于 CI 会话通常是短暂的,因此应该直接获取 etc/profile.d/conda.sh 以添加 conda activate 支持。

类似于:

conda env create -f python/env/foo.yml \
  && . "$(conda info --base)/etc/profile.d/conda.sh" \
  && conda activate foo