简体   繁体   English

conda 环境在 conda env 列表中没有可见的名称 - 如何在 shell 中激活它?

[英]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.我在 anaconda-navigator 中创建了一个名为 B3 的环境。 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.'但是,当我想在 shell 中激活它时,我得到“找不到环境 B3”。

If I use conda env list, the environment is visible but its name is blank.如果我使用 conda env list,环境是可见的,但它的名称是空白的。 If I try using the file path instead, I get 'Not a conda environment.'如果我尝试改用文件路径,我会得到“不是 conda 环境”。

Why is the name missing, and how can I activate it from the shell?为什么缺少名称,如何从 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 ). Conda 环境的基于名称的引用仅适用于位于envs_dirs配置选项中列出的目录之一的环境(请参阅conda config --describe envs_dirs )。 By default this corresponds to the envs/ subdirectory in the Conda installation.默认情况下,这对应于 Conda 安装中的envs/子目录。 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)选项 0:通过路径激活(修复 OP 的错字)

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

Note that OP originally had a typo ( anaconda2 should have been anaconda3 ).请注意,OP 最初有一个错字( anaconda2应该是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选项 1:克隆到目录

One option to use conda activate B3 , is to recreate your B3 env in the default directory.使用conda activate B3的一种选择是在默认目录中重新创建B3环境。 You can use the --clone flag to accomplish this.您可以使用--clone标志来完成此操作。

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

Option 2: Add Parent Directory选项 2:添加父目录

Alternatively, you can add the parent directory of the environment in question to the envs_dirs configuration option.或者,您可以将相关环境的父目录添加到envs_dirs配置选项。

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.另一种可能性是在一个envs_dirs文件夹中创建一个符号链接到环境文件夹。 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:当您使用 --prefix 创建一个 conda env 时,它不会有名称,请执行以下操作:

# 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.由于在两条不同的路径中installation of miniforge3 and miniconda ,因此在Apple M1 chip上遇到了类似的问题。

My solution Edit the .bash_profile我的解决方案编辑 .bash_profile

It is most likely that you have ps1 value set to False, which enables prompt change with change of conda environment.您很可能将 ps1 值设置为 False,这可以随着 conda 环境的变化而迅速更改。

To check run from your ubuntu terminal:要从您的 ubuntu 终端检查运行:

$ conda config --show | grep changeps1

And set it to True using:并使用以下方法将其设置为 True:

$ conda config --set changeps1 True

After this, you should see the currently activated conda environment name at the beginning of each prompt.在此之后,您应该在每个提示的开头看到当前激活的 conda 环境名称。 PS - You may have to close and reopen the terminal for this to take effect. PS - 您可能必须关闭并重新打开终端才能使其生效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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