62

I have created an environment called B3 inside anaconda-navigator. It works fine if launched from within navigator.

However, when I want to activate it at the shell, I get 'could not find environmnet B3.'

If I use conda env list, the environment is visible but its name is blank. If I try using the file path instead, I get 'Not a conda environment.'

Why is the name missing, and how can I activate it from the shell? enter image description here

julianhatwell
  • 1,074
  • 1
  • 8
  • 17
  • 1
    You're doing it right, just looks like a typo: `anaconda2` when it should be `anaconda3` in the path. – merv Aug 16 '19 at 15:34
  • What I really need to know is why it doesn't have a name and how can I launch it with conda activate B3 - as I would expect to. It is a pain to type in the whole path. – julianhatwell Aug 18 '19 at 14:17
  • 1
    Maybe figure out which `conda` is being used. It looks like there could be confusion between anaconda 2 and anaconda3 or miniconda3 setups, that each might have different defaults. I get different missing aliases if I use `/opt/anaconda3/bin/conda env list` vs `~/anaconda/bin/conda env list` – Dave X May 11 '21 at 17:20

6 Answers6

84

Name-based reference of Conda environments only works for environments located in one of the directories listed in the envs_dirs configuration option (see conda config --describe envs_dirs). By default this corresponds to the envs/ subdirectory in the Conda installation. If you create an env outside of one of these directories, then you cannot use a name to reference it. Instead, one must activate it by its path:

Option 0: Activate by Path (Fix OP’s Typo)

conda activate /home/julianhatwell/anaconda3/envs/B3

Note that OP originally had a typo (anaconda2 should have been anaconda3). After pointing this out (see comments to question), the questioner instead requested an answer to:

How to convert a nameless environment to named one?

Converting to Named Environment

The following are possible ways to enabling name-based activation.

Option 1: Clone Into Directory

One option to use conda activate B3, is to recreate your B3 env in the default directory. You can use the --clone flag to accomplish this.

conda create --clone path/to/the/nameless_env -n named_env

Option 2: Add Parent Directory

Alternatively, you can add the parent directory of the environment in question to the envs_dirs configuration option.

conda config --append envs_dirs /path/to/the/parent_dir

Another possibility is to create a symbolic link in one to the envs_dirs folders to the environment folder. It seems to work, but it is not a common practice, so it may have downsides that are unreported.

merv
  • 67,214
  • 13
  • 180
  • 245
  • Thank you. can you say why it was created outside the default directory? This is the only one I created manually from within anaconda-navigator. The rest were done by a script from my laptop supplier. Why is conda create not putting my environment into the default directory? – julianhatwell Aug 29 '19 at 19:05
  • @julianhatwell I can't give a definitive answer. I'd start by checking whether the Conda-specific variables are different in the two contexts. I.e., check `conda info` perhaps with a verbosity flag. – merv Aug 29 '19 at 20:13
  • How do you clone a nameless env though? – Cos Jun 15 '20 at 15:08
  • 3
    @Cos the `--clone` argument accepts paths, e.g., `conda create --clone path/to/the/nameless_env -n named_env`. – merv Jun 15 '20 at 16:38
  • 4
    I believe Option 2 above should be `conda config --append envs_dirs /path/to/the/parent_dir` – Sven Sep 18 '20 at 10:50
  • Please add option 4 : conda activate (answer by Nir below). Was the only way to go in my use case. – werner Jul 21 '21 at 12:15
  • @werner the history here is that the OP tried that, but simply had a typo when typing the path. After I pointed that out, the questioner specified that their question really was: “*How to convert a nameless env to a named env?*” And so that’s what I answered. But, because OP never updated, others arrive at this question that simply want what OP was already (incorrectly) doing. I suppose I could add it for quick reference, since it is the answer to the stated question (“*How to activate?*). – merv Jul 21 '21 at 18:50
  • 1
    @merv: you are right, that was exactly my intend. People don't care what the original question was if they find a good answer to their's ;-) – werner Aug 03 '21 at 15:59
  • Option 2 is exactly the answer for Orange3 – H.C.Chen Jan 03 '22 at 07:32
9

When you create a conda env with --prefix, it will not have a name, and to give one do the following:

# ex path: /Users/username/opt/miniconda3/envs/`
conda config --append envs_dirs <path to env folder here>

To activate the environment:

conda activate <name of the env>
Shaido
  • 27,497
  • 23
  • 70
  • 73
Nassima Noufail
  • 177
  • 1
  • 2
9

To get the list of the available environments use:

conda env list

To activate the nameless environment use:

conda activate <Folder>
Mathias711
  • 6,568
  • 4
  • 41
  • 58
Nir
  • 1,618
  • 16
  • 24
  • 1
    This tip just saved me a lot of hassle of recreating a VM, installing GPU drivers etc. Thanks so much! – MJB Nov 23 '20 at 23:03
  • 1
    **Minor note:** `conda env list` works by checking the `envs_dirs` directories and a *user-specific* file, `~/.conda/environments.txt`. Path-based environments get tracked by Conda using that file whenever a user creates or activates an environment by a path. There could still be other valid path-based environments on a volume that Conda will never know about unless the user activates them. For example, environments created by other users won't automatically be found. – merv Jun 22 '21 at 04:59
0

It is most likely that you have ps1 value set to False, which enables prompt change with change of conda environment.

To check run from your ubuntu terminal:

$ conda config --show | grep changeps1

And set it to True using:

$ conda config --set changeps1 True

After this, you should see the currently activated conda environment name at the beginning of each prompt. PS - You may have to close and reopen the terminal for this to take effect.

Bharath Kumar
  • 893
  • 9
  • 8
  • This is the correct solution when I have nuked my .bashrc and .profile by mistake. Thanks! – Mazen May 22 '22 at 19:09
0

Faced a similar issue on Apple M1 chip due to installation of miniforge3 and miniconda in two different paths.

My solution Edit the .bash_profile

Hemant c
  • 133
  • 1
  • 5
0

you can use conda rename as following (not need to change conda config):

$ conda rename -p path/to/env-123 env-123

you can get the path with conda env list

source: https://anaconda.cloud/conda-rename-command

Elinor
  • 56
  • 4