Launching sbatch jobs with a conda environment loaded can cause unexpected behavior
Open
@wwarriner is already working on this.
Since Apr 27, 2025.
style: article/section 📝
style: faq (ask.ci) ❓
system: cheaha 🖧
- Dominant language
- Python
- Stars
- 24
- Forks
- 15
- Avg merge
- 10d 3h
- Merged PRs (30d)
- 1
Description
Root Cause
- By default,
sbatchhas--export=ALL, so that all environment variables are exported to the submitted job context. condaworks by modifying environment variables and then checking them to decide how to behave when commands are run.- "Ghost" Conda environments can exist when jobs are started from a terminal where a
condaenvironment is loaded. Ifmodule loadis used,PATHwill have unexpected state, causing the Conda base python executable to be used over the Conda environment python executable.
Sequence of Events
- When you submit a job with a Conda environment already loaded, all of the Conda variables are set in the job context.
- In the job context, you then perform a
module load Miniforge3ormodule load Anaconda3to makecondaavailable. This puts the/share/apps/rc/software/<module>/binahead of/home/<user>/conda/envs/<env>/bininPATH. - Then you perform
conda activate <env>. condasees that<env>is already loaded using some subset ofCONDA_variables, so it does not modifyPATH. This is a "ghost" Conda environment.- Then
which pythonreturns an unexpected environment because thePATHvariable is in an unexpected state.
Good Practice for Launching sbatch Jobs
- Start from a fresh terminal, not a subprocess.
- If a conda environment is loaded use
conda deactivate. - Use
module reset. - Use your required
sbatchcommands.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.