Bash uses Python from Anaconda even it's deactivated

Viewed 107

Summary: Even I deactivate conda environment with conda deactivate, when I type python (or python3) on bash, python from conda starts.

Background: Normally I use pipenv to handle python dependencies. But earlier I have installed conda too, to train some ML models with GPU, because I couln't manage run GPU using pipenv.

But I don't really want to use both conda and pipenv, so I decided to get rid of conda to see if I manage to run GPU only using pipenv.

But when I try to deactivate conda and work with default python, it still there:

(base) user@tower:~$ conda deactivate
user@tower:~$ python
Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
user@tower:~$ python3
Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

What do you suggest, can I try to run some python code without using conda? If I can't, how can I completely get rid of conda?

I am open to any advice.

Info 1: Output of $PATH before and after deactivating it are the same as:

-bash: /home/foouser/.local/bin:/home/foouser/.local/bin:/home/foouser/anaconda3/bin:/home/foouser/anaconda3/bin:/home/foouser/anaconda3/condabin:/usr/local/cuda-9.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/foouser/.vimpkg/bin: No such file or directory

Anaconda section in ~/.bashrc:

# added by Anaconda3 2018.12 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/home/foouser/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/home/foouser/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/foouser/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/home/foouser/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<

# added by Anaconda3 installer
export PATH="/home/foouser/anaconda3/bin:$PATH"

export PATH="/home/foouser/.local/bin:/home/foouser/anaconda3/bin:/home/foouser/anaconda3/bin:/home/foouser/anaconda3/condabin:/usr/local/cuda-9.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/foouser/.vimpkg/bin"

Info 2: Output of which -a python:

/home/foouser/anaconda3/bin/python
/usr/bin/python

Edit-1: Edited bashrc after suggestion:

export PATH=/usr/local/cuda-9.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH

export PATH="/home/foouser/.local/bin:$PATH"

# added by Anaconda3 2018.12 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/home/foouser/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/home/foouser/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/foouser/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/home/foouser/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<

# added by Anaconda3 installer
# export PATH="/home/foouser/anaconda3/bin:$PATH"

# export PATH="$PATH:/home/foouser/.vimpkg/bin"
# export PATH="/home/foouser/.local/bin:$PATH"
# export PATH="/home/foouser/.local/bin:/home/foouser/anaconda3/bin:/home/foouser/anaconda3/bin:/home/foouser/anaconda3/condabin:/usr/local/cuda-9.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/foouser/.vimpkg/bin"                                                                                                                                                                                        
1 Answers

The problem comes from the following lines, which go against the post-Conda v.4.4 best practices (i.e., don't manually manipulate PATH to add Conda):

# added by Anaconda3 installer
export PATH="/home/foouser/anaconda3/bin:$PATH"

export PATH="/home/foouser/.local/bin:/home/foouser/anaconda3/bin:/home/foouser/anaconda3/bin:/home/foouser/anaconda3/condabin:/usr/local/cuda-9.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/foouser/.vimpkg/bin"

The first one should be deleted altogether. The second one should have all the paths containing anaconda3 removed. Also, it is completely overwriting your original PATH. You should rework it so that only what you need to manually add is either prepended, e.g.,

export PATH="/home/foouser/.local/bin:$PATH"

or appended, e.g.,

export PATH="$PATH:/home/foouser/.vimpkg/bin"

I would also move this to before the # >>> conda init >>> section.

Related