Why are conda and mamba not fully activating my environment on Cheaha?

When I use conda activate myenv or mamba activate myenv, my environment myenv seems to only be partially activate.

My terminal prompt shows the first line below. I expect to see the second line.

(base) [researcher@login004 ~]$
(myenv) [researcher@login004 ~]$

When I use conda env list I see the following, in conflict with the previous point.

myenv               *  /home/researcher/.conda/envs/myenv
                       # ... other environments omitted
base                   /share/apps/rc/software/Anaconda3/2022.05

When I use conda list I see packages from myenv, again in conflict with the apparently activated environment as seen from the terminal prompt. When I attempt to use a package in myenv, the corresponding package from base is used or there is an error message about missing packages.

What is going wrong and what can I do about this?

This issue results from using conda init on Cheaha. As a reminder, please do not use conda init even if conda or mamba instruct or recommend its use. Using conda init can result in unusual and hard-to-diagnose issues like this one.

Please see this answer to a similar question for details on resolving the issue.

I use ‘source activate myenv’ rather than 'conda ’ or ‘mamba activate’. Using ‘source activate’ avoids requiring ‘conda init’ and all the problems it entails. This might not be the ideal strategy, but it is one that works for us at our site.

Thanks for the comment, source activate definitely does work on our system with Anaconda, and we used to recommend that method. We use lmod to manage core software, including Anaconda, and a couple of years ago modified the lmod script so that conda activate works as expected on our system. The devs did it in a repeatable way so we avoid regression when upgrading. Our researchers are quite happy, we stopped getting tickets about 'conda activate` not working.

I had looked into this a lot at our site. The cause is that, in bash for sure at least, only shell built-in or shell function commands can edit environment variables in the current shell process. The “conda” command is both a shell function and an executable. Without the shell function, “conda activate myenv” is still a valid command, but it does not edit your PATH or PS1, so it’s not actually loading the environment. Without the “conda” function, conda will also give you those suggestions to run “conda init”.

Whenever “conda activate myenv” is not working, this usually means you do not have the “conda” function in your environment. This was a problem for our group until we added the shell functions from /path/to/anaconda/basedir/etc/profile.d/conda.sh to our Lmod modulefile. In Lmod there are a couple ways to source this “conda.sh” file directly, but I found at least in version v8.4 it wasn’t parsing everything correctly.

“source activate myenv” works because you’re using the “source” shell built-in, and do not require the “conda” shell function or its dependent shell functions. You just need the activate/deactivate executables to exist in your PATH.