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 command python
on Linux (Ubuntu 12.04 (Precise Pangolin))?

- 30,738
- 21
- 105
- 131

- 13,244
- 23
- 67
- 115
-
2Place Python you want to be the default as the first one on the `PATH`? – Piotr Dobrogost Jul 09 '14 at 22:03
-
1in response to Piotr's comment, here is the command: `export PATH="/Users/YOURNAME/miniconda3/bin:$PATH"` – Charlie Parker Jun 07 '20 at 19:49
-
Can you paste the contents of what the conda init function added for your case? (btw how did you end up solving the problem?) – Charlie Parker Jun 07 '20 at 19:53
-
For me the conda init does add (to the `.zhrc`) the export command I pasted above but for some reason there is a nested set of if statements that prevent the export from being run. I'm not sure why, but that might be what's happening to you too. Anyway, adding the above after the piece of code that conda init added to my `.zshrc` worked. – Charlie Parker Jun 07 '20 at 19:54
-
Do you want to use Anaconda or just Python? – Zack Plauché Dec 07 '21 at 21:10
10 Answers
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.

- 30,738
- 21
- 105
- 131

- 176,452
- 29
- 245
- 321
-
6+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. – Aditya Kashi Feb 21 '17 at 20:10
-
2
-
1Hi, 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? – dingx May 05 '19 at 04:35
-
-
what is wrong with doing: `export PATH="/Users/YOURNAME/miniconda3/bin:$PATH"`? that seemed to work for me. – Charlie Parker Jun 07 '20 at 19:53
-
@CharlieParker, It is exactly the same. `$HOME` expands to `/home/user`. It is just shorthand for writing it out and developers are lazy... – Padraic Cunningham Jun 09 '20 at 14:56
-
What's annoying is, the conda `pip` also shadows the system `pip`. So if I install dependencies using (conda) `pip` and install another Python binding, which by default use system `Python`, it will fail to work. So for me changing the `PATH` variable is a better solution. – HongboZhu Jul 06 '21 at 08:56
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"

- 391
- 4
- 12
-
-
1This worked for me on MacOS with anaconda installed via `brew cask install anaconda`: `export PATH="$PATH:/usr/local/anaconda3/bin"` – P A N Jun 07 '18 at 07:59
-
1This 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. – Kate Stohr May 17 '20 at 02:54
-
Because 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 https://www.baeldung.com/linux/path-variable for more details). – Asta86 May 22 '20 at 00:05
-
for 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 Jun 07 '20 at 19:51
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.

- 30,738
- 21
- 105
- 131

- 91
- 1
- 2
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
.

- 30,738
- 21
- 105
- 131

- 1,471
- 18
- 27
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.

- 3,247
- 14
- 49
- 93
I found that, though I remove export=.../anaconda3/bin:$PATH
, there is still .../anaconda3/envs/py36/bin
(my virtual environment in Anaconda) in PATH
, and the shell still uses Anaconda Python.
So I export PATH=/usr/bin:$PATH
(/usr/bin
is where system Python reside). Though there is already /usr/bin
inPATH
, we make it searched before the path of Anaconda, and then the shell will use the system Python when you key python
, python3.6
, pip
, pip3
....
You can get back to Anaconda by using an alias like mentioned above, or default to Anaconda again by comment export PATH=/usr/bin:$PATH
.

- 30,738
- 21
- 105
- 131

- 73
- 9
There are python
, python2
and python2.7
shortcuts in both the /home/username/anaconda/bin/
and /usr/bin/
directory. So you can delete any one of them from one folder and use that for the other.
I mean, if you delete the python2
shortcut from the Anaconda directory, you will have the Python for Anaconda version and
python2
for the default version in the terminal.

- 30,738
- 21
- 105
- 131

- 11
- 1
I use Anaconda sparingly to build cross-platform packages, but I don't want to use it as my daily driver for Python. For Anaconda, Ruby, and Node.js projects I've adopted to use environment sand-boxing, which essentially hides functionality behind a function away from your path until you specifically need it. I first learned about it from these two GitHub repositories:
https://github.com/benvan/sandboxd
https://github.com/maximbaz/dotfiles
I have a file of sandboxing functions that looks like this:
.zsh/sandboxd.zsh:
#!/bin/zsh
# Based on
# https://github.com/maximbaz/dotfiles/.zsh/sandboxd.zsh
# which was originally adapted from:
# https://github.vom/benvan/sandboxd
# Start with an empty list of all sandbox cmd:hook pairs
sandbox_hooks=()
# deletes all hooks associated with cmd
function sandbox_delete_hooks() {
local cmd=$1
for i in "${sandbox_hooks[@]}";
do
if [[ $i == "${cmd}:"* ]]; then
local hook=$(echo $i | sed "s/.*://")
unset -f "$hook"
fi
done
}
# Prepares the environment and removes hooks
function sandbox() {
local cmd=$1
# NOTE: Use original grep, because aliased grep is using color
if [[ "$(type $cmd | \grep -o function)" = "function" ]]; then
(>&2 echo "Lazy-loading '$cmd' for the first time...")
sandbox_delete_hooks $cmd
sandbox_init_$cmd
else
(>&2 echo "sandbox '$cmd' not found.\nIs 'sandbox_init_$cmd() { ... }' defined and 'sandbox_hook $cmd $cmd' called?")
return 1
fi
}
function sandbox_hook() {
local cmd=$1
local hook=$2
#echo "Creating hook ($2) for cmd ($1)"
sandbox_hooks+=("${cmd}:${hook}")
eval "$hook(){ sandbox $cmd; $hook \$@ }"
}
.zshrc
In my .zshrc
I create my sandbox'd function(s):
sandbox_hook conda conda
This command turns the normal conda
executable into:
conda () {
sandbox conda
conda $@
}
An added bonus of using this technique is that it speeds up shell loading times because sourcing a number of wrapper scripts (e.g. nvm
, rvm
, etc.) can slow your shell startup time.
It also bugged me that Anaconda installed its Python 3 executable as python
by default, which breaks a lot of legacy Python scripts, but that's a separate issue. Using sandboxing like this makes me explicitly aware that I'm using Anaconda's Python instead of the system default.

- 30,738
- 21
- 105
- 131

- 634
- 1
- 12
- 28
-
-
1I'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` – cbcoutinho Apr 13 '18 at 14:05
Anaconda 3 adds more than a simple line in my .bashrc file. However, it also backs up the original .bashrc file into a .bashrc-anaconda3.bak file.
So my solution was to swap the two.

- 30,738
- 21
- 105
- 131

- 65
- 5
For my case, when I had
alias python='/usr/bin/python3.6'
in the ~/.bashrc
, it always called python3.6
inside and outside of Anaconda Virtual Environment.
In this setting, you could set the Python version by python3
in each Virtual Environment.

- 1,594
- 19
- 22