How do I switch back to python2 after Anaconda set python3 as the default?
I went through the installation in a VM, and the following happend.
- The installer asks for an install location. Default is
/home/myuser/anaconda3
. At the end you'll be asked
Python 3.5.1 :: Continuum Analytics, Inc. creating default environment... installation finished. Do you wish the installer to prepend the Anaconda3 install location to PATH in your /home/myuser/.bashrc ? [yes|no] [no] >>> yes Prepending PATH=/home/myuser/anaconda3/bin to PATH in /home/myuser/.bashrc A backup will be made to: /home/myuser/.bashrc-anaconda3.bak
To restore the old behavior, go to your home directory and do
mv .bashrc-anaconda3.bak .bashrc
then start a new shell.
As you suggest, you could alias python=python2
, but I find that a bit weird.
I would
- Restore the original
.bashrc
- Create (if it does not exist)
~/bin
- Link
ln -s ~/anaconda3/bin/python3 ~/bin/python3
- [Prepend
$HOME/bin
to$PATH
](Should already be set by default by~/.profile
) - Relogin.
That way, calling python3
will start the one from Anaconda.
An important point is, that the original
/usr/bin/python
is still there, and still points to python2.7
. The ramifications of having python->python3
in your path depend on how a specific script is called.
If the shebang #!/usr/bin/python
is used, like it probably is in all executables that ship with Ubuntu, nothing will change.
On the other hand, for better portability #!/usr/bin/env python
is sometimes used, which will now cause python3.5
to be called.
Good answer here: https://stackoverflow.com/questions/24405561/how-to-install-2-anacondas-python-2-7-and-3-4-on-mac-os-10-9
conda create -n python2 python=2.7 anaconda
then, to switch:
source activate python2
In case anyone is looking to change their python default version back to 2.7 after messing it up(by changing default one to: anaconda or python 3) and ending up with non-functional software, just follow this link: Link with instructions to change default python version.