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?
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}) '