Conda env not available on ci but available locally

I'm running installing a conda env:

conda env create -f python/env/foobar.yml && . "$(conda info --base)/etc/profile.d/conda.sh" && conda activate foobar

Then running the python command:

/usr/local/envs/foobar/bin/python foobar.py

This command works locally (macos) but for some reason in the github ci (ubuntu), this gives the following error: "Cannot run program "/usr/local/envs/foobar/bin/python": error=2, No such file or directory" Why is this not working?


Generally, I would not recommend directly pointing at binaries in Conda environments as shown. This is because environments often have activation steps that set shell variables, and expected behavior of binaries can be dependent on those settings.

Typically, users activate the environment, then allow the software to be resolved by the shell. Something like,

conda activate foobar
python foobar.py

Alternatively, the conda run command allows for executing within an environment without manipulating the active shell. For example,

conda run -n foobar python foobar.py

Note that conda run defaults to buffering output (i.e., not interactive), but there are flags (see conda run -h) that can enable alternative modes.