11

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.

0

5 Answers 5

16

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.*
4
  • 2
    That's fine, ofc. But I'd suggest using environments, that way you can create as many python envs as you want and switch between them using source activate/deactivate: conda.io/docs/using/envs.html
    – Samuel
    Feb 24, 2017 at 21:17
  • I have the above added to ~/.bashrc however which python does not return the anaconda3 version..... do I need to reboot for it to take effect? Just installed anaconda.
    – user391339
    Feb 23, 2018 at 19:37
  • # added by Anaconda3 installer export PATH="/home/d/anaconda3/bin:$PATH"
    – user391339
    Feb 23, 2018 at 19:38
  • 2
    Ah, I got it. You need to refresh the environment variables either by re-opening a new terminal or typing source ~/.bashrc
    – user391339
    Feb 23, 2018 at 19:40
3

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.

1

After you installed Anaconda, just run

source ~/.bashrc

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

1

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

0

UPDATE FOR 2019+

In a new versions of Anaconda it is not recommended to add conda/bin to path manually. While installation ask you about run conda init press yes - conda will do all necessary option by itself.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .