Use the default Python rather than the Anaconda installation when called from the terminal
Solution 1
Anaconda adds the path to your .bashrc
, so it is found first. You can add the path to your default Python instance to .bashrc
or remove the path to Anaconda if you don't want to use it.
You can also use the full path /usr/bin/python
in Bash to use the default Python interpreter.
If you leave your .bashrc
file as is, any command you run using python
will use the Anaconda interpreter. If you want, you could also use an alias
for each interpreter.
You will see something like export PATH=$HOME/anaconda/bin:$PATH
in your .bashrc
file.
So basically, if you want to use Anaconda as your main everyday interpreter, use the full path to your default Python or create an alias
. If you want it the other way around, remove the export PATH=...
. from bashrc
and use full path to Anaconda Python interpreter.
Solution 2
Having tried all the suggestions so far, I think modifying the export statement in file ~/.bashrc, as Piotr Dobrogost seems to suggest, is the best option considering the following:
- If you remove the whole statement, you have to use full paths for Conda binaries.
- Using Conda 4.4.10 links in the directory anaconda/bin/ point to binaries in the same directory, not the system ones in /usr/bin.
- Using this approach you get the system programs for all that have been previously included in $PATH and also the ones specific to anaconda without using full paths.
So in file ~/.bashrc instead of
# Added by the Anaconda3 4.3.0 installer
export PATH="/home/user/anaconda3/bin:$PATH"
one would use
export PATH="$PATH:/home/user/anaconda3/bin"
Solution 3
I faced the same issue and you can do the following.
Go into your .bashrc file and you will find a similar sort of line:
export PATH=~/anaconda3/bin:$PATH
You comment it out and instead type out:
alias pyconda='~/anaconda3/bin/python3'
Or whatever your path is. This worked out for me.
Solution 4
at 2020, like the @spacetyper mentioned, it acted differently. I've found a handy solution for that from this question: How do I prevent Conda from activating the base environment by default?
To disable automatic base activation:
conda config --set auto_activate_base false
it'll create a ./condarc
in home directory after running the first time.
Solution 5
In the year 2020, Conda adds in a more complicated block of code at the bottom of your .bash_profile
file that looks something like this:
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/spacetyper/opt/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/Users/spacetyper/opt/miniconda3/etc/profile.d/conda.sh" ]; then
. "/Users/spacetyper/opt/miniconda3/etc/profile.d/conda.sh"
else
export PATH="/Users/spacetyper/opt/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
To use the default Python install by default: Simply move this section of code to the very top of your .bash_profile
file.
To give yourself the option of using the Conda installed Python: Add this line below the Conda code block above.
alias pyconda="/Users/spacetyper/opt/miniconda3/bin/python3"
Now you should be able to call the system Python install with python
and the Conda install with pyconda
.
Michael
Updated on July 05, 2022Comments
-
Michael almost 2 years
I recently installed the Anaconda version of Python. Now when I type
python
into the terminal it opens the Anaconda distribution rather than the default distribution. How do I get it to use the default version for the commandpython
on Linux (Ubuntu 12.04 (Precise Pangolin))? -
Aditya Kashi about 7 years+1 for the alias idea. In fedora 25, I can add "alias python=/usr/bin/python", and now when I say "python" or "python2" I get the system python 2.7, but if I say "python3" I get the conda python. The advantage of this is that system tools which rely on python 2.7 (like gnome-tweak-tool) work fine.
-
Guig about 6 yearsI also had to change my
~/.bash_profile
in the same way -
sg7 about 6 yearsThis does not seem to address the OP question.
-
Mr. Unnormalized Posterior about 6 yearsHow do I use this?
-
cbcoutinho about 6 yearsI'd recommend looking at the dotfiles I linked to above use it for a good example, but most simply you need to source the sandboxing functions in your
~/.bashrc
or~/.zshrc
, and then create a sandbox for conda by placing the following after sourcing the sandboxing functions:sandbox_hook conda conda
-
P A N almost 6 yearsThis worked for me on MacOS with anaconda installed via
brew cask install anaconda
:export PATH="$PATH:/usr/local/anaconda3/bin"
-
toofrellik about 5 yearsWhat needs to be changed if we have a similar issue in Windows
-
dingx about 5 yearsHi, conda added a section rather than a simple line: "# >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! __conda_setup="$('/home/dingxin/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then eval "$__conda_setup" else if [ -f "/home/dingxin/anaconda3/etc/profile.d/conda.sh" ]; then . "/home/dingxin/anaconda3/etc/profile.d/conda.sh" else export PATH="/home/dingxin/anaconda3/bin:$PATH" fi fi unset __conda_setup # <<< conda initialize <<" . how to deal with it in this case?
-
mah65 over 4 yearsWhere to find .bashrc in windows?? I want to use python in cmd.
-
Kate Stohr almost 4 yearsThis worked. I am curious. Please can you explain why adding the shell command '$PATH' in front of the path rather than trailing the path prevents conda from being called as the default python interpreter.
-
Asta86 almost 4 yearsBecause in that case the interpreter located in for instance /usr/bin is found before the one in the anaconda directory, and the first match is utilized (check baeldung.com/linux/path-variable for more details).
-
Charlie Parker almost 4 yearsfor me the first one you have works. I'm surprised you used the second one. My command:
export PATH="/Users/YOURNAME/miniconda3/bin:$PATH"
-
Charlie Parker almost 4 yearswhat is wrong with doing:
export PATH="/Users/YOURNAME/miniconda3/bin:$PATH"
? that seemed to work for me. -
Padraic Cunningham almost 4 years@CharlieParker, It is exactly the same.
$HOME
expands to/home/user
. It is just shorthand for writing it out and developers are lazy... -
Peter Mortensen over 3 yearsA .bak file on Linux?
-
Peter Mortensen over 3 yearsIsn't a VM something else?
-
Cloud Cho over 3 years@PeterMortensen You're right. I corrected to Virtual Environment.
-
HongboZhu almost 3 yearsWhat's annoying is, the conda
pip
also shadows the systempip
. So if I install dependencies using (conda)pip
and install another Python binding, which by default use systemPython
, it will fail to work. So for me changing thePATH
variable is a better solution.