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
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.
Best Answer
New answer:
From Conda 4.14 you will be able to use just:
Although, under the hood,
conda rename
still uses [1][2] undermentioned combination ofconda create
andconda remove
.Use the
-d
flag for dry-run (not destination, as of v22.11.0)Old answer:
You can't.
One workaround is to create clone a new environment and then remove the original one.
First, remember to deactivate your current environment. You can do this with the commands:
deactivate
on Windows orsource deactivate
on macOS/Linux.Then:
Notice there are several drawbacks of this method:
--offline
flag to disable it)There is an open issue requesting this feature.