Search code examples
pythonanacondaanaconda3

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


I used anaconda3 for a python3 install. And now it's my default python:

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

But I need python2 as my default python.

$ which python2
/usr/bin/python2

I tried to edit my .bashrc shown below,

# !! 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

By change the line of export PATH... to

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

It didn't change anything.

How should I set python2 back as the default?


Solution

  • I think the cleanest way to go forward is to do following changes:

    1) Edit your ~/.bashrc and do following modifications

    Keep this block. Do not edit it. If you already deleted it, you can recreate it by typing 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) Make sure you /home/xy/anaconda3/bin is not added to PATH outside of this block. If so, delete those.

    3) Call conda config --set auto_activate_base False in your shell

    From now on, you have to activate the anaconda environment manually with conda activate base. If you do not call this, you will default back to your system python.