問題描述
我在 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 中激活它?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!