515

I want to remove a certain environment created with conda. How can I achieve that? Let's say I have an active testenv environment. I tried, by following documentation, with:

$ conda env remove

CondaEnvironmentError: cannot remove current environment. deactivate and run conda remove again

I then deactivate it:

$ source deactivate

I try running again the command to remove it and I still get the same error. What is going wrong here?

MWB
  • 10,855
  • 6
  • 41
  • 80
renatodamas
  • 11,380
  • 5
  • 29
  • 43

19 Answers19

698

You probably didn't fully deactivate the Conda environment - remember, the command you need to use with Conda is conda deactivate (for older versions, use source deactivate). So it may be wise to start a new shell and activate the environment in that before you try. Then deactivate it.

You can use the command

conda env remove -n ENV_NAME

to remove the environment with that name. (--name is equivalent to -n)

Note that you can also place environments anywhere you want using -p /path/to/env instead of -n ENV_NAME when both creating and deleting environments, if you choose. They don't have to live in your conda installation.

UPDATE, 30 Jan 2019: From Conda 4.6 onwards the conda activate command becomes the new official way to activate an environment across all platforms. The changes are described in this Anaconda blog post

holdenweb
  • 27,899
  • 7
  • 50
  • 73
159

After making sure your environment is not active, type:

$ conda env remove --name ENVIRONMENT
renatodamas
  • 11,380
  • 5
  • 29
  • 43
  • 4
    This is the information I needed. Would have been nice if `conda env --help` had given it. – R. Schreurs Mar 22 '19 at 09:51
  • `EnvironmentLocationNotFound: Not a conda environment: /home/user/.conda/envs/ENVIRONMENT ` – user924 Mar 29 '19 at 07:43
  • 2
    I submitted a bug about failures to update the help text, and it was marked as an easy issue for beginners, so there's hope of a fix. – holdenweb Apr 29 '19 at 11:58
  • It is hard to believe that we need to come here to get this basic info. The conda website returns no information when 'delete environment' is used as search terms. – Antonio Sesto Oct 24 '21 at 10:26
67

Official documentation way worked for me:

conda remove --name myenv --all

Or just conda env remove --name myenv.

To verify that the environment was removed, in your terminal window or an Anaconda Prompt, run:

conda info --envs

The environments list that displays should not show the removed environment.

You anaconda3 enviroments folder might list an empty folder of deleted environment in your anaconda3 installation folder, like:

/opt/anaconda3/envs
Hrvoje
  • 10,368
  • 5
  • 67
  • 78
54

If you are in base:

(base) HP-Compaq-Elite-8300-CMT:~$ 

remove env_name by:

conda env remove -n env_name

if you are already in env_name environment :

(env_name) HP-Compaq-Elite-8300-CMT:~$ 

deactivate then remove by :

conda deactivate
conda env remove -n env_name
M.Innat
  • 13,008
  • 6
  • 38
  • 74
Shilpa Shinde
  • 795
  • 6
  • 8
46

In my windows 10 Enterprise edition os this code works fine: (suppose for environment namely testenv)

conda env remove --name testenv
dipakbera
  • 461
  • 3
  • 2
39

Environments created with the --prefix or -p flag must be removed with the -p flag (not -n).

For example: conda remove -p </filepath/myenvironment> --all, in which </filepath/myenvironment> is substituted with a complete or relative path to the environment.

Chris Keefe
  • 666
  • 6
  • 16
  • 1
    My environment name included a space, like *my env*. This method, `conda env remove -p path/to/my\ env` worked while `conda env remove -n my\ env` and `conda env remove -n "my env"` did not. – Ben Oct 24 '19 at 02:28
35

There're 3 ways to achieve this in total. Assuming you have a environment named myenv,

  1. conda env remove --name myenv, -n is shortcut for --name.

  2. conda remove --name myenv --all.

  3. Delete the env folder directly. (Not recommended)

    # list environments and their locations
    conda env list
    # or
    # conda info --envs
    
    # delete the folder listed
    rm -rf /Users/username/.local/share/conda/envs/myenv
    

If you wanna delete the environment without a prompt to let you check again. Use -y, shortcut for --yes. (For global use check silent prompt in conda)

conda env remove -n myenv -y
conda remove -n myenv --all -y

References

  • conda env --help
  • conda remove --help
Simba
  • 17,532
  • 3
  • 48
  • 64
  • 7
    And why is deleting the env folder directly not recommended? What could possibly go wrong? – NoName Jun 13 '20 at 15:57
  • 1
    @NoName Conda provides packages with a hookable pre-unlink event fired prior to package removal. Deleting directly would skip this. AFAICT, it's rarely used and mostly manages things internal to the env (e.g., a Jupyter *extension* will de-register itself with the Jupyter instance through such hooks), so deleting everything shouldn't break stuff. However, [searching turns up some packages](https://github.com/search?q=org%3Aconda-forge+unlink&type=code) (e.g., FSL-related packages) that appear to register externally, in which case manual deletion might leave dangling references. – merv Aug 06 '21 at 05:03
19

You may try the following: Open anaconda command prompt and type

conda remove --name myenv --all

This will remove the entire environment.

Further reading: docs.conda.io > Manage Environments

B--rian
  • 5,011
  • 10
  • 34
  • 73
Muhamad Mohsin
  • 224
  • 2
  • 3
16

To remove complete conda environment :

conda remove --name YOUR_CONDA_ENV_NAME --all

0x90
  • 37,093
  • 35
  • 149
  • 233
Bhadru Bhukya
  • 359
  • 3
  • 3
15

First you have to deactivate your environment before removing it. You can remove conda environment by using the following command

Suppose your environment name is "sample_env" , you can remove this environment by using

source deactivate    
conda remove -n sample_env --all

'--all' will be used to remove all the dependencies

14

My environment name is: test

conda remove -n test --all
francescalus
  • 27,974
  • 11
  • 58
  • 92
CodeUrLife
  • 371
  • 4
  • 5
10

Use source deactivate to deactivate the environment before removing it, replace ENV_NAME with the environment you wish to remove:

source deactivate
conda env remove -n ENV_NAME
ntg
  • 10,762
  • 7
  • 62
  • 81
Jason
  • 1,712
  • 20
  • 18
  • 7
    An explanation, what a code does and how this addresses the problem in the question, rarely fails to improve an answer. – MBT Nov 10 '18 at 16:02
  • `EnvironmentLocationNotFound: Not a conda environment: /home/user/.conda/envs/ENV_NAME` – user924 Mar 29 '19 at 07:44
6

First deactivate the environment and come back to the base environment. From the base, you should be able to run the command conda env remove -n <envname>. This will give you the message

Remove all packages in environment C:\Users\<username>\AppData\Local\Continuum\anaconda3\envs\{envname}:

CAPSLOCK
  • 4,735
  • 3
  • 28
  • 49
Deepak
  • 143
  • 1
  • 2
5

This worked for me:

conda env remove --name tensorflow
Bart
  • 1,292
  • 5
  • 31
Arman Samimi
  • 59
  • 1
  • 2
  • Worked for me too. ```conda env remove --name ``` Later you can delete the environment folder from Anaconda or miniconda install location ```Anaconda\envs\``` or ```Miniconda\envs\``` – Giriraj Pawar Apr 22 '20 at 07:24
1

if you are unfamiliar with the command line , you can remove it using the anaconda dashboard

enter image description here

0

View the environments in Anaconda or miniconda:

conda env list

If you have created an environment using name then use:

conda remove -n envname --all

if you have created an environment using prefix then use:

conda remove -p [path] --all

Change the envname with your environment name and in case of prefix provide the complete path of the environment eg: C:/Users/techv/Desktop/project/env.
--all will remove all the dependencies of the target environment.

I hope this answer will be helpful.

Vineet Singh
  • 59
  • 1
  • 8
0
  1. First deactivate the environment that you wish to remove.

  2. Then type the following code:

    conda env remove -n <your environment name>

  3. To make sure you have deleted it, you can use the following code.

    conda info --envs or conda env list

4.If you wan to remove all the dependencies along with the installed packages, you can use:

conda remove -n <environment name> --all
-1

Because you can only deactivate the active environment, so conda deactivate does not need nor accept arguments. The error message is very explicit here.

Just call conda deactivate https://github.com/conda/conda/issues/7296#issuecomment-389504269

-3

on terminal it's showing

(base) [root@localhost ~]#

simply hit command : conda deactivate

and you are out of conda env , now your prompt will look like

[root@localhost ~]#

  • The answer does not provide any new insights. It was already mentioned to run this command as root. – avans Apr 13 '21 at 12:48