How to set anaconda as a default python?

I have just installed the Anaconda (for ipython notebook -- wanted to run some pandas programme). It is installed successfully but the problem here is whenever I type which python, it is always using a default python as /usr/bin/python

It will be great if someone can tell me how to setup the anaconda python as a default python. I am noob here till now I have just installed the anaconda in the default path as following ~/anaconda3.

Thanks in advance.


Solution 1:

I have the same setup as you desire. In my case the anaconda installer added an entry in my ~/.bashrc file. I don't know why yours did not. So to get to do what you want, add this to your ~/.bashrc file:

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

You need to refresh your env variables after this by opening a new terminal or using source ~/.bashrc

With this:

$ which python
/home/yash/anaconda3/bin/python

And python -v returns: anaconda

To get back to the former default, I comment out the entry setting the pathbin the .bashrc file and get these results:

$ which python
/usr/bin/python
$ python -v
python 2.7.*

Solution 2:

Instead of adding the entry in ~/.bashrc add the entry in ~/.profile or ~/.bash_profile as it is a path and not an alias. Also, adding the path in bashrc may slower the terminal unnecessarily. To know the detailed meaning of ~/.bashrc and it's difference with the profile visit this link.

Solution 3:

After you installed Anaconda, just run

source ~/.bashrc

If you open the .bashrc file you can see it added Anaconda python to environment variable.

Solution 4:

Setting anaconda3 python as default can be tricky espesially if you have several shells like zsh and bash. This means you have to include PATH variable in the default .rc file. An easy fix is just to add

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

to your ~/.profile file. Then source the file by running source ~/.profile in a terminal.

Verify that it works by running which python. you should see /home/username/anaconda3/bin/python