770

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?

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
renatodamas
  • 16,555
  • 8
  • 30
  • 51
  • 4
    Make sure you're running the terminal as an administrator otherwise commands will run successfully without throwing any error but env will not be removed. – Krishna Jan 26 '19 at 08:21

20 Answers20

1130

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 remove -n ENV_NAME --all

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

UPDATE, 24 Feb 2023: The conda env subcommand has been deprecated. Now, the officially recommended way is conda remove -n ENV_NAME --all. You can update to the latest version with conda install -n base -c defaults conda (sometimes it helps to specify the new version with eg ... -c defaults conda=23.3.1).

Roelant
  • 4,508
  • 1
  • 32
  • 62
holdenweb
  • 33,305
  • 7
  • 57
  • 77
  • You're right, my mistake when writing the post. I meant `source deactivate`. Thank you – renatodamas Mar 06 '18 at 10:04
  • 10
    Actually you can use `conda deactivate` as well and it works likewise. At least in the version 4.4.11 – renatodamas Mar 06 '18 at 10:11
  • Thanks. But not just `deactivate` on its own, right? – holdenweb Mar 08 '18 at 07:27
  • Yes, either `source deactivate` or `conda deactivate` – renatodamas Mar 08 '18 at 09:25
  • `EnvironmentLocationNotFound: Not a conda environment: /home/user/.conda/envs/ENVIRONMENT ` – user924 Mar 29 '19 at 07:43
  • 1
    Do yourself a favor and run this after you use `conda env remove`: `rm -rf ~/anaconda/envs/ENV_NAME` if you use the default anaconda install location. – rjurney Apr 17 '19 at 18:25
  • 4
    If deleting an environment leaves anything behind I'd imagine that the Anaconda team would appreciate a bug report. – holdenweb Apr 18 '19 at 16:07
  • 2
    also if you create a prefix it will work: conda env remove -p << prefix path >> – Cornea Valentin Jun 05 '19 at 08:39
  • What I did before was that I just removed the folder containing the virtual environment. Is it bad to the system integrity? – Wei Shan Lee Mar 04 '22 at 07:06
  • 1
    It's unlikely you'd mess anything up by removing the folder, but I'm a big fan of using recommended methods just in case anything changes. – holdenweb Mar 04 '22 at 14:09
  • why not describe in this answer what --all does? – PascalIv Mar 04 '23 at 15:36
  • 2
    If you're like me and remove conda environments to create space on the disk, remember to do a conda clean to delete cached packages after removing the environment, e.g. `conda clean -a` Read more here before doing it https://docs.conda.io/projects/conda/en/latest/commands/clean.html – tu_curious Jun 14 '23 at 22:27
266

After making sure your environment is not active, type:

$ conda remove --name ENVIRONMENT --all
Cornelius Roemer
  • 3,772
  • 1
  • 24
  • 55
renatodamas
  • 16,555
  • 8
  • 30
  • 51
  • 7
    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
  • 1
    `EnvironmentLocationNotFound: Not a conda environment: /home/user/.conda/envs/ENVIRONMENT ` – user924 Mar 29 '19 at 07:43
  • 4
    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
  • What is the conda version that brought this command into existence? It din't work on conda 4.14.0 . – qqqqq Mar 23 '23 at 17:14
96

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
  • 13,566
  • 7
  • 90
  • 104
65

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
Innat
  • 16,113
  • 6
  • 53
  • 101
Shilpa Shinde
  • 961
  • 8
  • 10
51

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

conda env remove --name testenv
dipakbera
  • 519
  • 4
  • 2
45

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
  • 797
  • 7
  • 17
36

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
  • 23,537
  • 7
  • 64
  • 76
  • 8
    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
31
  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
dilip_nikhil
  • 369
  • 3
  • 6
  • What is environment name and where i get it from please dont post half of the information. Your question should be complete – Haseeb Mir Feb 12 '23 at 14:22
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,578
  • 10
  • 38
  • 89
Muhamad Mohsin
  • 224
  • 2
  • 3
17

To remove complete conda environment :

conda remove --name YOUR_CONDA_ENV_NAME --all

0x90
  • 39,472
  • 36
  • 165
  • 245
Bhadru Bhukya
  • 369
  • 3
  • 3
16

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

15

My environment name is: test

conda remove -n test --all
francescalus
  • 30,576
  • 16
  • 61
  • 96
CodeUrLife
  • 391
  • 4
  • 5
11

First I checkout from the environment (tensorflow):

conda deactivate

Then I removed the environment by:

conda remove -n tensorflow --all

The tensorflow is the name of my environment

You can check your env name using this command:

conda env list
Ashok Chhetri
  • 428
  • 6
  • 10
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
  • 12,950
  • 7
  • 74
  • 95
Jason
  • 1,974
  • 24
  • 19
  • 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
  • 6,243
  • 3
  • 33
  • 56
Deepak
  • 153
  • 1
  • 2
5

This worked for me:

conda env remove --name tensorflow
Bart
  • 1,405
  • 6
  • 32
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
5

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
  • 309
  • 5
  • 12
4

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

enter image description here

Mohamed TOUATI
  • 372
  • 2
  • 4
-2

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

-6

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 ~]#