繁体   English   中英

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

我尝试编辑如下所示的 my.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 设置为默认值?

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

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 conda activate base手动激活 anaconda 环境。 如果你不调用这个,你会默认回到你的系统 python。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM