Conda environment name shows entire directory in prompt
Asked Answered
P

2

8

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.

Pinnate answered 14/1, 2017 at 23:29 Comment(0)
P
10

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 ❯❯❯ 
Patmore answered 19/1, 2017 at 5:2 Comment(6)
The command "conda config --show" shows an error: "conda config: error: one of the arguments --get --add --set --remove --remove-key is required"Pinnate
@Learnaholic What is the version of conda that you are using?Patmore
Try updating conda to 4.3.5 and see if the problem persists?Patmore
Cool thanks, that did it, although upgrading conda also upgraded my python. :-/Pinnate
Also, "conda activate myEnv" doesnt work, it says you have to do "source activate myEnv".Pinnate
This doesn't appear to work anymore in 4.5.11. Even if you add the path to envs_dirs, it still prints the whole path.Lidialidice
D
4

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

Doralynn answered 10/1, 2021 at 11:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.