Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the default python path for anaconda on Linux?

I have installed anaconda on a Linux machine. I noticed that after deactivating the anaconda environment with:

source deactivate

When running:

which python

I get:

/home/user/anaconda/bin/python

Instead of

/usr/bin/python

How can I restore this setting?

like image 631
catthe Avatar asked Mar 11 '23 03:03

catthe


2 Answers

The comments somewhat cover the answer to the question, but to clarify:

When you installed Anaconda you must have agreed to have it added to your PATH. You'll want to check in your ~/.bash* files and look for any export PATH= lines to check this. So Anaconda is always on your path. The source deactivate command will only deactivate "sub" Conda environments. It will never remove what is called the "root" Conda environment (the one you originally installed). If you don't want Anaconda on your PATH by default then remove it from your ~/.bash* startup files. Then when you want to use Anaconda you'll need to add it to your PATH. Or just add the specific Conda environment you are interested in to your PATH directly, and don't worry about the activate and deactivate scripts. At their core all they do is modify PATH.

I hope that helps clarify things.

like image 96
IanSR Avatar answered Mar 13 '23 16:03

IanSR


Anaconda comes with its own everything, and they ask if you wish to use their software as a default when you install it by adding their bin first to your PATH variable. If you do that, you can only manually remove it later from .bashrc to undo this action.

I chose not to do it, but i made a shell script to start spyder and use the anaconda distribution when i wish to, without altering my PATH by calling spyder like this from the shell script:

PATH=/home/<... path to where i installed anaconda>/bin:$PATH spyder &

This means that i am adding their distribution's bin to the path only for the extent of running that command (spyder), otherwise my environment is unaffected by anaconda.

If i wish to add things to it, i pass an option to the shell when i source it and that triggers these actions:

PATH=/home/<... path to where i installed anaconda>/bin:$PATH
PS1='\[\033[1;34m\](A)\w:\[\033[0m\] '

so that i see (with colors!) that in this terminal i am using an altered PATH, the one with python3 and such from anaconda, etc... When done, i kill the terminal! :)

like image 45
vuvu Avatar answered Mar 13 '23 17:03

vuvu