問(wèn)題描述
我在 anaconda-navigator 中創(chuàng)建了一個(gè)名為 B3 的環(huán)境.如果從導(dǎo)航器中啟動(dòng)它就可以正常工作.
I have created an environment called B3 inside anaconda-navigator. It works fine if launched from within navigator.
但是,當(dāng)我想在 shell 中激活它時(shí),我得到找不到 environmnet B3".
However, when I want to activate it at the shell, I get 'could not find environmnet B3.'
如果我使用 conda env list,環(huán)境是可見(jiàn)的,但它的名稱(chēng)是空白的.如果我嘗試改用文件路徑,我會(huì)得到不是 conda 環(huán)境".
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.'
為什么缺少名稱(chēng),如何從 shell 激活它?
Why is the name missing, and how can I activate it from the shell?
推薦答案
基于名稱(chēng)的 Conda 環(huán)境引用僅適用于位于 envs_dirs
配置選項(xiàng)中列出的目錄之一的環(huán)境(請(qǐng)參閱 <代碼>conda config --describe envs_dirs).默認(rèn)情況下,這對(duì)應(yīng)于 Conda 安裝中的 envs/
子目錄.如果您在這些目錄之一之外創(chuàng)建環(huán)境,則不能使用名稱(chēng)來(lái)引用它.相反,必須通過(guò)它的路徑來(lái)激活它:
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
請(qǐng)注意,OP 最初有一個(gè)錯(cuò)字(anaconda2
應(yīng)該是 anaconda3
).在指出這一點(diǎn)后(見(jiàn)問(wèn)題的評(píng)論),提問(wèn)者要求回答:
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:
如何將無(wú)名環(huán)境轉(zhuǎn)換為有名環(huán)境?"
以下是啟用基于名稱(chēng)的激活的可能方法.
The following are possible ways to enabling name-based activation.
使用 conda activate B3
的一個(gè)選項(xiàng)是在默認(rèn)目錄中重新創(chuàng)建 B3 環(huán)境.您可以使用 --clone
標(biāo)志來(lái)完成此操作.
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
選項(xiàng)2:添加父目錄
或者,您可以將相關(guān)環(huán)境的父目錄添加到 envs_dirs
配置選項(xiàng).
conda config --append envs_dirs /path/to/the/parent_dir
選項(xiàng) 3:符號(hào)鏈接
另一種可能性是在 envs_dirs
文件夾中創(chuàng)建一個(gè)符號(hào)鏈接到環(huán)境文件夾.它似乎有效,但它不是一種常見(jiàn)的做法,因此它可能具有未報(bào)告的缺點(diǎn).
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.
這篇關(guān)于conda 環(huán)境在 conda env 列表中沒(méi)有可見(jiàn)的名稱(chēng) - 如何在 shell 中激活它?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!