Fix Python – How can I rename a conda environment?

Question

Asked By – pkowalczyk

I have a conda environment named old_name, how can I change its name to new_name without breaking references?

Now we will see solution for issue: How can I rename a conda environment?


Answer

New answer:

From Conda 4.14 you will be able to use just:

conda rename -n old_name -d new_name 

Although, under the hood, conda rename still uses [1][2] undermentioned combination of conda create and conda remove.


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 or
  • source deactivate on macOS/Linux.

Then:

conda create --name new_name --clone old_name
conda remove --name old_name --all # or its alias: `conda env remove --name old_name`

Notice there are several drawbacks of this method:

  1. It redownloads packages (you can use --offline flag to disable it)
  2. Time consumed on copying environment’s files
  3. Temporary double disk usage

There is an open issue requesting this feature.

This question is answered By – pkowalczyk

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0