Conda activate error

Hello, I just encountered some problems on the discovery cluster.
I could not activate my conda environment with the slurm script:
#!/bin/bash
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=16
#SBATCH --time=24:00:00
conda activate cooler_env

When I used sbatch to submit this slurm file, it reported error, from the .out file: 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’.

However, when I request the node interactively, I was able to activate my conda environment cooler_env:
salloc --ntasks=1 --cpus-per-task=16 --time=24:00:100: salloc: Pending job allocation 820341
salloc: job 820341 queued and waiting for resources
salloc: job 820341 has been allocated resources
salloc: Granted job allocation 820341
salloc: Waiting for resource configuration
salloc: Nodes d17-43 are ready for job
(base) jiangxu@d17- 43:/scratch/jiangxu/CTCC/CTCC_SDS_with_RNaseA/pool_out/hic_results/data/CTCC2_with_RNase_over_100bp_pair_pool$ conda activate cooler_env
(cooler_env) jiangxu@d17-43:/scratch/jiangxu/CTCC/CTCC_SDS_with_RNaseA/pool_out/hic_results/data/CTCC2_with_RNase_over_100bp_pair_pool$ nano cooler_load_pair.slurm

So, what’s going on there?

Add this line before activating the environment:

eval "$(conda shell.bash hook)"

With Slurm jobs, your ~/.bashrc is not sourced, so it doesn’t initialize the shell for Conda environments.

1 Like

Thanks a lot. Problem solved after adding the line. :100: