【发布时间】:2020-09-06 23:13:24
【问题描述】:
我正在尝试在 Google Colaboratory 上使用 conda 创建一个虚拟环境。 但是,我无法激活并出现以下错误。
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
我尝试了两项改进。 我尝试了三个改进。 一种是将以下代码添加到~/.bashrc。
# >>> conda init >>>
__conda_setup="$(CONDA_REPORT_ERRORS=false '$HOME/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "$HOME/anaconda3/etc/profile.d/conda.sh" ]; then
. "$HOME/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="$PATH:$HOME/anaconda3/bin"
fi
fi
unset __conda_setup
# <<< conda init <<<
# ~~~~~~~~~~~~
conda create --name XXXXXX python=3.6 -y
conda activate XXXXXX
# ~~~~~~~~~~~~
其次,我在 ~/.bashrc 中添加了以下代码
export PATH="$PYENV_ROOT/versions/anaconda3-2.5.0/bin/:$PATH"
第三,我在 ~/.bashrc 中添加了如下代码
. /opt/anaconda3/etc/profile.d/conda.sh
conda activate base
如果我尝试激活它们中的每一个,我会得到同样的错误。如果有人明白,请分享你的智慧。
谢谢
【问题讨论】:
-
能否给出
echo $SHELL的输出。我怀疑你的 shell 没有加载~/.bashrc- 也许它使用了不同的文件。另外我建议撤消~/.bashrc中的所有修改,只使用conda init <shell-name>来修改它——尤其是后面的那些弊大于利。
标签: python bash anaconda conda google-colaboratory