激活conda虚拟环境CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate‘

conda activate env_name

出现以下提示:
CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate’.
在这里插入图片描述
原因:安装anaconda3时conda init没有选择yes
~/.bashrc文件中没有conda init的初始化信息

解决办法

vi ~/.bashrc

在conda activate env_name之前粘贴:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/ec2-user/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/ec2-user/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/ec2-user/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/ec2-user/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<
conda init
source ~/.bashrc

还是出现
CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate’.
输入

conda init

再次运行正常

source ~/.bashrc