[python] Removing Conda environment

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?

This question is related to python jupyter conda

The answer is


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

To remove complete conda environment :

conda remove --name YOUR_CONDA_ENV_NAME --all


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.


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

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

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}:


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


My environment name is: test

conda remove -n test --all

After making sure your environment is not active, type:

$ conda env remove --name ENVIRONMENT

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

conda env remove --name testenv

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

This worked for me:

conda env remove --name tensorflow

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


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


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


Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to jupyter

How to increase image size of pandas.DataFrame.plot in jupyter notebook? What is the difference between Jupyter Notebook and JupyterLab? Removing Conda environment How to open local file on Jupyter? Jupyter notebook not running code. Stuck on In [*] Can I run Keras model on gpu? IOPub data rate exceeded in Jupyter notebook (when viewing image) How to execute a * .PY file from a * .IPYNB file on the Jupyter notebook? how to make a new line in a jupyter markdown cell Running Jupyter via command line on Windows

Examples related to conda

Upgrade to python 3.8 using conda How do I prevent Conda from activating the base environment by default? Conda version pip install -r requirements.txt --target ./lib Removing Conda environment PackagesNotFoundError: The following packages are not available from current channels: Conda activate not working? ModuleNotFoundError: No module named 'sklearn' How do I update Anaconda? Conda command is not recognized on Windows 10 'Conda' is not recognized as internal or external command