Python: 使用anacoda3安装python 3后默认设置python2

Python: set python2 as the default after installing python 3 with anacoda3

我使用 anaconda3 进行 python3 安装。现在这是我的默认 python:

$ which python
/home/xy/anaconda3/bin/python
$ which python3
/home/xy/anaconda3/bin/python

但我需要 python2 作为我的默认值 python。

$ which python2
/usr/bin/python2

我尝试编辑如下所示的 .bashrc,

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

通过将 export PATH... 行更改为

export PATH="$PATH:/home/xy/anaconda3/bin"

它没有改变任何东西。

我应该如何将 python2 设置回默认值?

我认为最干净的前进方式是进行以下更改:

1) 编辑您的 ~/.bashrc 并进行以下修改

保留此块。不要编辑它。如果您已经删除了它,您可以通过键入 conda init bash.

重新创建它
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/xy/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/nu
ll)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/xy/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/xy/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/xy/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup

2) 确保你 /home/xy/anaconda3/bin 没有被添加到这个块之外的 PATH 中。如果是这样,请删除它们。

3) 在您的 shell

中调用 conda config --set auto_activate_base False

从现在开始,您必须使用 conda activate base 手动激活 anaconda 环境。如果你不调用这个,你将默认回到你的系统 python.