How to Run `conda activate` in a Shell Script
What if we try to run conda activate
in a bash or shell script?
conda activate <env_name>
We might encounter 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'.
We can run conda activate
in a bash/shell script if we first run
eval "$(conda shell.bash hook)"
.
eval "$(conda shell.bash hook)"
conda activate <env_name>
eval
allows us to execute a command from a string argument.
Run conda shell.bash hook
in terminal to get an idea of the conda init script that we’re executing.