4

If you create a python environment in conda with --prefix flag and activate it, post-activation the environment is shown by its entire path. This could be a very long path and hence the conda-documentation suggests a fix as follows.

conda config --set env_prompt '({name})'

The problem is when you deactivate this environment, then you don't go back to the default behavior. Even if you activate the base environment, it would show you the entire path of the base environment instead of just (base).

For instance, I installed the conda environment under path Users/username/Documents/GitHub/test_flask/.env on the C-drive (Windows 10). BEFORE applying the command (conda config --set env_prompt '({name})'), post activation it looks like this:

(C:\Users\username\Documents\GitHub\test_flask\.env) C:\Users\username\Documents\GitHub\test_flask>

And AFTER applying the command (conda config --set env_prompt '({name})'), if I activate the environment, it looks like this:

(.env) C:\Users\username\Documents\GitHub\test_flask>

Great! But now if I deactivate this environment and/or activate my base environment, I get this:

'(Anaconda3)'C:\Users\username\Documents\GitHub\test_flask>

However, I would like to get back:

'(base)'C:\Users\username\Documents\GitHub\test_flask>

So, how to fix this?

CypherX
  • 7,019
  • 3
  • 25
  • 37

5 Answers5

2

Solution

It turns out that you need to do the following to get back the default behavior. Here we set the default behavior of env_prompt variable in .condarc file, again before deactivating the environment that was installed at a non-default location.

Assuming you create your python-environment directory (.env) under your project directory as follows:

conda env create --prefix ./.env -f envirnment.yml

Follow these steps for activating and deactivating the environment.

# for activating env
conda config --set env_prompt '({name})'
conda activate ./.env


# for deactivating env
conda config --set env_prompt '({default_env})'
conda deactivate
conda activate base

Description of the env_prompt variable

Source: conda-config: .condarc file

### .condarc file (env_prompt section)

# # env_prompt (str)
# #   Template for prompt modification based on the active environment.
# #   Currently supported template variables are '{prefix}', '{name}', and
# #   '{default_env}'. '{prefix}' is the absolute path to the active
# #   environment. '{name}' is the basename of the active environment
# #   prefix. '{default_env}' holds the value of '{name}' if the active
# #   environment is a conda named environment ('-n' flag), or otherwise
# #   holds the value of '{prefix}'. Templating uses python's str.format()
# #   method.
# # 
# env_prompt: '({default_env}) '
CypherX
  • 7,019
  • 3
  • 25
  • 37
2

As far as I understand, commands beggining with conda env config vars should address such issues, but for some reason me changing env_prompt variable with such a command took no effect.

But I figured out an alternative way: all you need is just to put a brand-new .condarc file in the root of your environment. In your case, C:\Users\username\Documents\GitHub\test_flask\.env\.condarc. And such contents should be enough:

env_prompt: '({name}) '

Note that you may need to activate your environment twice (the first one to load local .condarc and the second one to apply it).

Alternative way to do so is to use --env option with conda config while desired environment being active:

conda activate .\.env
conda config --set env_prompt '({name})' --env

It seems to be more robust and convenient way but it was inappropriate for me because I was working in context of makefile.

If you use command conda info you are able to see which configuration files are in effect.

2

If you just want to return to the default setting, use the following command (as shown in the env_prompt section of the docs). In my case I had one of my environments active so I guess it is a global variable.

$ conda config --set env_prompt '({default_env}) '

Note that the change is visible after newly activating some environment, such as:

$ conda deactivate
$ conda activate base
1

There is a more babarian method ! The "issue" comes from the .condrac file.

  1. Deleting the file works (mine was located at C:\Users\username but the .condarc doc gives you other places if you don't find it). The next time you --set smth in the .condarc file, conda will re-summon it.

  2. If you already used the conda config command then you .condarc file probably countains other lines than just env_prompt: "...". Then find the file, open it (Notepad++ works well) and delete the affected line.

My OS : Win10-64 last version

LMWafer
  • 11
  • 1
0

I went into C:\Users and just looked at the bottom of the folder and deleted the .condarc file and I am able to activate all the environments after restarting Conda.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Shawn Jamal
  • 170
  • 8