简体   繁体   中英

conda environment has no name visible in conda env list - how do I activate it at the shell?

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? 在此处输入图像描述

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.

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>

To get the list of the available environments use:

conda env list

To activate the nameless environment use:

conda activate <Folder>

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM