添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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?

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, 2019 at 8:21

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

Actually you can use conda deactivate as well and it works likewise. At least in the version 4.4.11 – renatodamas Mar 6, 2018 at 10:11 If deleting an environment leaves anything behind I'd imagine that the Anaconda team would appreciate a bug report. – holdenweb Apr 18, 2019 at 16:07 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 4, 2022 at 14:09 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, 2019 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 at 17:14

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

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

conda env remove --name testenv

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.

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

  • conda remove --name myenv --all.

  • Delete the env folder directly. (Not recommended)

    # list environments and their locations
    conda env list
    # 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
  • And why is deleting the env folder directly not recommended? What could possibly go wrong? – NoName Jun 13, 2020 at 15:57 @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 (e.g., FSL-related packages) that appear to register externally, in which case manual deletion might leave dangling references. – merv Aug 6, 2021 at 5:03

    conda env remove -n <your environment name>

  • 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
                    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 at 14:22
    

    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

    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

    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
                    An explanation, what a code does and how this addresses the problem in the question, rarely fails to improve an answer.
    – MBT
                    Nov 10, 2018 at 16:02
    

    The tensorflow is the name of my environment

    You can check your env name using this command:

    conda env list
    

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

    Worked for me too. conda env remove --name <name of your environment> Later you can delete the environment folder from Anaconda or miniconda install location Anaconda\envs\<name of your environment> or Miniconda\envs\<name of your environment> – Giriraj Pawar Apr 22, 2020 at 7:24
    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.

    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

    (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, 2021 at 12:48
  •