I am trying to make a bash script to activate conda. The commands work in my terminal but not inside bash. What might the reason be? It isn't fixed by conda init
.
Minimal recreation steps, using bash -c instead of a bash file:
conda activate ./build/env
works
bash -c "conda activate ./build/env"
error:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
bash -c "conda init"
no benefit:
No action taken.
I am using miniconda.
My full script is:
#!/bin/bash --init-file
# Change to the current directory
cd "$(dirname "$(realpath "${BASH_SOURCE[0]}")")" || exit
if [ ! -d ./environment ]; then
mamba env create -p ./environment -f ./environment.yml
fi
conda activate ./environment
The purpose of the script is to make setting up the environment simpler. It is intended for the project to be used by many users after cloning from source control. The user must have conda and mamba installed (it will say this in a text document). My goal is ease of use so I would like it to 'just work' as much as possible, for example when executed with bash my_script.sh
and ./my_script.sh
.