CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'

Viewed 63311

I'm trying to create a virtual environment using conda on Google Colaboratory. However, I can't activate with the following error.

    CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init

Three things that I've tried: One is to add the following code to ~/.bashrc

# >>> conda init >>>
__conda_setup="$(CONDA_REPORT_ERRORS=false '$HOME/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "$HOME/anaconda3/etc/profile.d/conda.sh" ]; then
        . "$HOME/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="$PATH:$HOME/anaconda3/bin"
    fi
fi
unset __conda_setup
# <<< conda init <<<

# ~~~~~~~~~~~~
conda create --name XXXXXX python=3.6 -y
conda activate XXXXXX 
# ~~~~~~~~~~~~

Secondly, I added the following code to ~/.bashrc

export PATH="$PYENV_ROOT/versions/anaconda3-2.5.0/bin/:$PATH"

Thirdly, I added the following code to ~/.bashrc

. /opt/anaconda3/etc/profile.d/conda.sh
conda activate base

If I try to activate each of them, I get the same error. If anyone knows how to fix it, please share your wisdom.

Thanks

3 Answers

The answer is here: https://github.com/conda/conda/issues/7980

source ~/anaconda3/etc/profile.d/conda.sh
conda activate my_env

Maybe you're also using the wrong anaconda/miniconda path. Use the one which results from this command:

conda info | grep -i 'base environment'

:)

First you have to run

conda init <your terminal type>

eg:

conda init bash

you will get something like

no change     /home/t/anaconda3/condabin/conda
no change     /home/t/anaconda3/bin/conda
no change     /home/t/anaconda3/bin/conda-env
no change     /home/t/anaconda3/bin/activate
no change     /home/t/anaconda3/bin/deactivate
no change     /home/t/anaconda3/etc/profile.d/conda.sh
no change     /home/t/anaconda3/etc/fish/conf.d/conda.fish
no change     /home/t/anaconda3/shell/condabin/Conda.psm1
no change     /home/t/anaconda3/shell/condabin/conda-hook.ps1
no change     /home/t/anaconda3/lib/python3.9/site-packages/xontrib/conda.xsh
no change     /home/t/anaconda3/etc/profile.d/conda.csh
no change     /home/t/.bashrc

then close the current terminal window and open it again (reopen basically). Now if you type conda activate it should work

t@t:~$ conda activate
(base) t@t:~$ ^C
(base) t@t:~$ 

For me the last answer here worked. It's kind of inconvenient but better than nothing... So, if it's necessary to run something in the conda environment, I just put !source <path_to_activate_function> my_env before other commands, as follows:

!source ~/anaconda3/bin/activate vilbert-mt && conda env list
Related