Last updated: Apr 10, 2024
Reading timeยท4 min

The error "CondaEnvironmentError: cannot remove current environment" occurs for multiple reasons:
conda environment that is currently active.conda environment.base conda environment which cannot be deleted.
CondaEnvironmentError: cannot remove current environment. deactivate and run conda remove again
Open your terminal and issue the following command to deactivate the environment before removing it.
conda deactivate

After you deactivate the environment, issue the following command to remove it.
conda env remove -n ENVIRONMENT_NAME # ๐๏ธ Same as above conda env remove --name ENVIRONMENT_NAME
ENVIRONMENT_NAME placeholder with the name of the environment.Use the conda env list command if you need to list the names of your conda
environments.
conda env list

You can use the conda info --envs command to verify the environment has been
removed.
conda info --envs

If you get a permissions error on Windows, open CMD or Anaconda Prompt as an administrator and rerun the commands.
An alternative way to remove an environment is to use the -p flag.
-p flagThe -n flag allows us to specify the name of the environment, whereas the -p
flag allows us to specify the path to the environment.
Make sure the environment is not active by running the following command.
conda deactivate
Use the conda info --envs command to get the path to your conda environment.
conda info --envs

The path to the environment I want to remove is
/home/borislav/anaconda3/envs/myenv, so I would issue the following command.
conda env remove -p /home/borislav/anaconda3/envs/myenv # ๐๏ธ Same as above conda env remove --prefix /home/borislav/anaconda3/envs/myenv

conda environment with the -p or --prefix flag, you have to use the -p or --prefix flag to remove it.You can use the conda info --envs command to verify the environment has been
removed.
conda info --envs

You can also use the conda env list command to list your conda environments.
conda env list
If none of the suggestions helped, you can delete the directory that contains
your conda environment.
conda environmentMake sure the environment is not active by running the following command.
conda deactivate
Use the conda info --envs command to get the path to your conda environment.
conda info --envs

The path in my case is /home/borislav/anaconda3/envs/myenv, so I would issue
the following command.
conda environment as rm -rf is a destructive command.# ๐๏ธ For macOS and Linux rm -rf /home/borislav/anaconda3/envs/myenv

If you are on Windows, you would issue the following command.
rd /s /q "/home/borislav/anaconda3/envs/myenv"
Make sure to update the path based on the output of the conda info --envs
command.
You can use the conda info --envs command to verify the environment has been
removed.
conda info --envs

Note that you cannot delete the default base conda environment. The only way
to delete the base environment is to uninstall Anaconda.
However, you can revert the base environment to its initial state.
base conda environment to its initial stateMake sure to deactivate your environment before reverting the base conda
environment to its initial state.
conda deactivate
Only run the following command if you want to revert the base conda
environment to its initial state.
This would uninstall any of the additional modules you have installed into the environment.
conda install --name base --revision 0
The command will remove the packages you installed in your base conda
environment.
To solve the error "CondaEnvironmentError: cannot remove current environment":
conda environment before removing it.conda env remove -n ENVIRONMENT_NAME command to remove the
environment.You can learn more about the related topics by checking out the following tutorials: