Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 677
Leo.H Avatar asked May 20 '20 14:05

Leo.H


People also ask

How do I activate conda?

To activate your Conda environment, type source activate <yourenvironmentname> . Note that conda activate will not work on Discovery with this version. To install a specific package, type conda install -n <yourenvironmentname> [package] . To deactivate the current, active Conda environment, type conda deactivate .

How do I run a conda in bash?

for anaconda 4 : bashrc and then copy the path into the file and save it after that you activate the changes using source . bashrc. When I type export PATH=~/anaconda3/bin:$PATH into the terminal and then run conda --version it works fine.

How do you activate conda's base environment in your current shell session?

you can simply add the anaconda bin folder (eg.: ~/anaconda3/bin ) to the system PATH and then source activate ENV_NAME in your ~/. bashrc or ~/.


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'

:)

like image 130
effecor Avatar answered Sep 20 '22 13:09

effecor


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
like image 34
TopCoder2000 Avatar answered Sep 17 '22 13:09

TopCoder2000


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:~$ 
like image 43
Tikendra Kumar Sahu Avatar answered Sep 17 '22 13:09

Tikendra Kumar Sahu