How to use conda activate commands inside a bash

Yuwei BaoSeptember 9, 2023

Issue:

When I try to run a bash script TEST_activate_conda.sh like following:

#!/bin/bash

conda activate py38_GR

samclip --version

where my base conda doesn't have the software samclip, but the py38_GR conda environment has the software.

I see the 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'.

Solution [1]

Firstly, find the path to anaconda

conda env list

Then modify the script like following

#!/bin/bash

source PATH_TO/anaconda3/etc/profile.d/conda.sh

conda activate py38_GR

samclip --version

Then we see

samclip 0.4.0

Attempt that doesn't work

conda init bash
modified      PATH_TO_anaconda3/condabin/conda
modified      PATH_TO_anaconda3/bin/conda
modified      PATH_TO_anaconda3/bin/conda-env
no change     PATH_TO_anaconda3/bin/activate
no change     PATH_TO_anaconda3/bin/deactivate
no change     PATH_TO_anaconda3/etc/profile.d/conda.sh
no change     PATH_TO_anaconda3/etc/fish/conf.d/conda.fish
no change     PATH_TO_anaconda3/shell/condabin/Conda.psm1
no change     PATH_TO_anaconda3/shell/condabin/conda-hook.ps1
no change     PATH_TO_anaconda3/lib/python3.9/site-packages/xontrib/conda.xsh
no change     PATH_TO_anaconda3/etc/profile.d/conda.csh
no change     PATH_TO/.bashrc

Kill this terminal, start a new terminal but it doesn't work.


  1. https://stackoverflow.com/questions/61915607/commandnotfounderror-your-shell-has-not-been-properly-configured-to-use-condaopen in new window ↩︎