How to use the python default interpreter instead of miniconda's base python interpreter

230 Views Asked by At

My default python interpreter has been set to conda's base environment python interpreter. I would want my default /usr/bin/python3 to be the default.

I've looked at this question which suggests that changing the ordering in PATH would work. However I'm a fish user, so the task becomes a bit more tedious.

Just changing the PATH environment variable using set -U PATH <my path> doesn't work probably because of the following section in my config.fish

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
if test -f /home/cmaspi/miniconda3/bin/conda
    eval /home/cmaspi/miniconda3/bin/conda "shell.fish" "hook" $argv | source
end
# <<< conda initialize <<<

Here conda "shell.fish" "hook" is probably the culprit that changes PATH, but I'm not sure. How do I change the path such that my good old /usr/bin/python3 becomes my default?

2

There are 2 best solutions below

1
faho On BEST ANSWER

In short: fish_add_path can be told to move a path to the front of $PATH:

fish_add_path --path --move /usr/bin

("--move" tells it to move already included paths, "--path" tells it to operate on $PATH directly)

This will take care to only leave one /usr/bin in $PATH, and if it already is in front it won't do anything.

If you have a $PATH of

/usr/bin /usr/local/bin

and conda sets it to

/path/to/conda/bin /usr/bin /usr/local/bin

this will turn it into

/usr/bin /path/to/conda/bin /usr/local/bin

You could also store your old $PATH and move all those parts to the front:

set -l oldpath $PATH
/home/cmaspi/miniconda3/bin/conda shell.fish hook | source
fish_add_path --move --path $oldpath

Or you could move the conda components to the back of $PATH with --append (using the actual paths my installation uses):

/home/cmaspi/miniconda3/bin/conda shell.fish hook | source
fish_add_path --move --path --append /opt/miniconda3/bin /opt/miniconda3/condabin

The conda invocation here isn't doing anything magic.

It prints code, and source then reads that code. You can just inspect it by running /path/to/conda shell.fish hook, and see what it prints.

The important bit here is conda activate base right at the end. conda is a function that the hook defines, and if you follow it you see that conda activate base would end up running

eval ($CONDA_EXE shell.fish activate base)

(where $CONDA_EXE is the path to conda)

This is another command that ends up printing fish code, and you can run it and see that conda shell.fish activate base prints, among other things:

set -gx PATH "/opt/miniconda3/bin" "/opt/miniconda3/condabin" "/usr/local/sbin" "/usr/local/bin" "/usr/bin" "/usr/bin/site_perl" "/usr/bin/vendor_perl" "/usr/bin/core_perl";

where "/opt/miniconda3/bin" and "/opt/miniconda3/condabin" are new and the rest is my old $PATH. So it really just adds these components in front.

2
Guapi-zh On

You can maybe add the PATH variable to include "/usr/bin" as the first directory. You can use the set command and place this command before the Conda initialization block:

# Set the default Python interpreter
set -x PATH /usr/bin $PATH

# >>> conda initialize >>>
if test -f /home/cmaspi/miniconda3/bin/conda
    eval /home/cmaspi/miniconda3/bin/conda "shell.fish" "hook" $argv | source
end
# <<< conda initialize <<<

# Other Fish shell configurations
# ...

# Alias to use 'python' to run Python 3
alias python /usr/bin/python3

Remember to source the file to apply these changes.