75

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

4
  • 2
    You're doing it right, just looks like a typo: anaconda2 when it should be anaconda3 in the path.
    – merv
    Commented Aug 16, 2019 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. Commented Aug 18, 2019 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
    Commented May 11, 2021 at 17:20
  • I Think it may be you helpfull: stackoverflow.com/a/78119770/17745835
    – GeM
    Commented Mar 28 at 5:26

7 Answers 7

103

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.

10
  • 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? Commented Aug 29, 2019 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
    Commented Aug 29, 2019 at 20:13
  • 3
    @Cos the --clone argument accepts paths, e.g., conda create --clone path/to/the/nameless_env -n named_env.
    – merv
    Commented Jun 15, 2020 at 16:38
  • 4
    I believe Option 2 above should be conda config --append envs_dirs /path/to/the/parent_dir
    – Sven
    Commented Sep 18, 2020 at 10: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
    Commented Aug 3, 2021 at 15:59
13

To get the list of the available environments use:

conda env list

To activate the nameless environment use:

conda activate <Folder>
3
  • 1
    This tip just saved me a lot of hassle of recreating a VM, installing GPU drivers etc. Thanks so much!
    – MJB
    Commented Nov 23, 2020 at 23:03
  • 2
    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
    Commented Jun 22, 2021 at 4:59
  • how does one delete the nameless environment? Commented Feb 18 at 15:15
11

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>
4

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

1
  • 1
    Technically, this "renames" with a lot of quotes, the src environment. It is actually cloning the environment and removign any alias to the original one.
    – CheTesta
    Commented Sep 15, 2023 at 13:13
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.

1
  • This is the correct solution when I have nuked my .bashrc and .profile by mistake. Thanks!
    – Mazen
    Commented May 22, 2022 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

0

In addition to the answer of @merv , you can also change your envs_dirs by editing ~/.condarc file directly. You can use conda config command to firstly create this file if it doesn't exist yet.

$ cat ~/.condarc
channels:
  - conda-forge
envs_dirs: ['/xxx/xxx/']

Not the answer you're looking for? Browse other questions tagged or ask your own question.