问题描述
我在 anaconda-navigator 中创建了一个名为 B3 的环境.如果从导航器中启动它就可以正常工作.
I have created an environment called B3 inside anaconda-navigator. It works fine if launched from within navigator.
但是,当我想在 shell 中激活它时,我得到找不到 environmnet B3".
However, when I want to activate it at the shell, I get 'could not find environmnet B3.'
如果我使用 conda env list,环境是可见的,但它的名称是空白的.如果我尝试改用文件路径,我会得到不是 conda 环境".
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.'
为什么缺少名称,如何从 shell 激活它?
Why is the name missing, and how can I activate it from the shell?
推荐答案
基于名称的 Conda 环境引用仅适用于位于 envs_dirs
配置选项中列出的目录之一的环境(请参阅 <代码>conda config --describe envs_dirs).默认情况下,这对应于 Conda 安装中的 envs/
子目录.如果您在这些目录之一之外创建环境,则不能使用名称来引用它.相反,必须通过它的路径来激活它:
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:
conda activate /home/julianhatwell/anaconda3/envs/B3
请注意,OP 最初有一个错字(anaconda2
应该是 anaconda3
).在指出这一点后(见问题的评论),提问者要求回答:
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:
如何将无名环境转换为有名环境?"
以下是启用基于名称的激活的可能方法.
The following are possible ways to enabling name-based activation.
使用 conda activate B3
的一个选项是在默认目录中重新创建 B3 环境.您可以使用 --clone
标志来完成此操作.
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
选项2:添加父目录
或者,您可以将相关环境的父目录添加到 envs_dirs
配置选项.
conda config --append envs_dirs /path/to/the/parent_dir
选项 3:符号链接
另一种可能性是在 envs_dirs
文件夹中创建一个符号链接到环境文件夹.它似乎有效,但它不是一种常见的做法,因此它可能具有未报告的缺点.
Option 3: Symbolic Link
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.
这篇关于conda 环境在 conda env 列表中没有可见的名称 - 如何在 shell 中激活它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!