Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conda environment name shows entire directory in prompt

When I run:

source activate /anaconda2/envs/myEnv

it shows the entire directory of this conda environment in my prompt (on iterm2) as so:

(/Users/billy/anaconda2/envs/myEnv)billy@mbp:~/projects

Is this a way to shorten this, so that it just shows the name of the conda environment and not the entire directory? For example as:

(myEnv)billy@mbp:~/projects

Thanks.

like image 206
Spacey Avatar asked Feb 05 '23 08:02

Spacey


2 Answers

You can try the following:

Make sure that /anaconda2/envs is listed in the section envs_dirs in the output for the command:

$ conda config --show

If it is not present, you can add it like this:

$ conda config --add envs_dirs /anaconda2/envs

Then, activate the environment like this:

$ source activate myEnv

Example:

(root) ~/condaexpts ❯❯❯ conda create -yp /tmp/miniconda2/myEnv
Fetching package metadata .......
.Solving package specifications: .
Package plan for installation in environment /tmp/miniconda2/myEnv:

The following empty environments will be CREATED:

/tmp/miniconda2/myEnv

#
# To activate this environment, use:
# > source activate /tmp/miniconda2/myEnv
#
# To deactivate this environment, use:
# > source deactivate /tmp/miniconda2/myEnv
#

(root) ~/condaexpts ❯❯❯ conda config --add envs_dirs /tmp/miniconda2
(root) ~/condaexpts ❯❯❯ source activate myEnv
(myEnv) ~/condaexpts ❯❯❯ 
like image 131
Nehal J Wani Avatar answered Feb 09 '23 02:02

Nehal J Wani


You can set the env_prompt option in the config file, see Specifying a location for an environment.

One option is conda config --set env_prompt '({name})' or you can edit the .condarc in your home directory. Just add env_prompt: '({name})'.

like image 34
upe Avatar answered Feb 09 '23 03:02

upe