Is there a way to get a nicer environment prompt when using CONDA_ENVS_DIRS?

I work in an academic environment where lots of users with very limited home directory quotas are trying to spin up conda environments and running are out of space. So I’ve been working on setting up a multi-user miniconda base on an NFS filesystem shared to all (linux) desktops. What I can’t do is make any of the directories in /mnt/opt/miniconda world or even group writable (as suggested here: Installing for multiple users — Anaconda documentation) because we have many hundreds of users and not all of them are trustworthy. Even so, this works fairly well save for one detail. I took a run at this a few years ago and made notes suggesting that if an ordinary user activates a shared environment and tries to conda install a package, it goes to ~/.conda/pkgs rather than the shared location (they don’t have write access to), but the package is nevertheless accessible to them from the activated environment. Testing this with the current version of conda (23.7.4), this clearly doesn’t work and I’m not sure what I was doing previously.

The second best solution is to set up /mnt/opt/miniconda/user-envs/$USER folders which are writable by $USER, so that all environments are on the same filesystem. Astute readers will notice that packages installed in users ~/.conda directories will be actual packages and not hard links, because you can’t hard link across filesystems.

export CONDA_ENVS_DIRS=/mnt/miniconda/user-envs/$USER

This doesn’t work unless you also set CONDA_PKGS_DIRS:

export CONDA_PKGS_DIRS=/home/$USER/.conda/pkgs
export CONDA_ENVS_DIRS=/mnt/opt/miniconda/user-envs/$USER

This works, but when you activate an environment from $USER the prompt becomes the full path to the environment location. In this example, the first activated environment is from the shared environment, the second is one I set up under $USER:

$ source /mnt/opt/miniconda/bin/activate
(base) pgoetz@texas-tea ~$ conda activate numpy                                              
(numpy) pgoetz@texas-tea ~$ conda activate pytorch                                           
(/mnt/opt/miniconda/user-envs/pgoetz/pytorch) pgoetz@texas-tea ~$

It would be nicer if the prompt were just

(pytorch) pgoetz@texas-tea ~$

Is there any way to make this happen?

1 Like

A possible workaround is to manipulate Conda’s PS1 prompt (as in this SO answer), however, that will also impact any subsequent prefix-based activations.

The behavior - which I’ve confirmed - is a bit surprising, since conda env list will correctly give names. That is, this seems like inconsistent behavior where the CONDA_PROMPT_MODIFIER is not adequately considering all the envs_dirs.

In lieu of that being addressed in conda itself, using .condarc files to push settings rather than environment variables should not have the same issue. But these would need to be user-specific, since I do not believe they support shell variables.

Hi, and thanks for your response. I tried the suggestion in the linked stackoverflow post. This seems not to work until you realize that you have to deactivate and then re-activate the environment before it takes effect:

pgoetz@texas-tea ~$ source /mnt/opt/miniconda/bin/activate pytorch
(/mnt/opt/miniconda/user-envs/pgoetz/pytorch) pgoetz@texas-tea ~$ conda config --set env_prompt '({name}) '
(/mnt/opt/miniconda/user-envs/pgoetz/pytorch) pgoetz@texas-tea ~$
(/mnt/opt/miniconda/user-envs/pgoetz/pytorch) pgoetz@texas-tea ~$ conda deactivate
pgoetz@texas-tea ~$ source /mnt/opt/miniconda/bin/activate pytorch
(pytorch) pgoetz@texas-tea ~$

What’s happening when you run conda config --set env_prompt '({name}) ' is it creates a .condarc file in your home directory:

pgoetz@texas-tea ~$ cat .condarc
env_prompt: '({name}) '

So one can just create this a priori as well. There is one very odd side effect, namely activating base no longer shows the (base) prompt:

$ source /mnt/opt/miniconda/bin/activate
(miniconda) pgoetz@texas-tea ~$

However, this seems like a perfectly acceptable compromise to me. I’m going to mark this as solved.