删除Conda环境

问题:删除Conda环境

我想删除使用conda创建的特定环境。我该如何实现?假设我有一个活跃的testenv环境。我通过遵循文档尝试了:

$ conda env remove

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

然后我将其停用:

$ source deactivate

我尝试再次运行命令将其删除,但仍然出现相同的错误。这是怎么了?

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?


回答 0

您可能没有完全停用Conda环境-请记住,您需要在Conda中使用的命令是conda deactivate(对于旧版本,请使用source deactivate)。因此,在尝试之前,启动一个新的Shell并在其中激活环境可能是明智的。然后停用它。

您可以使用以下命令

conda env remove -n ENV_NAME

删除具有该名称的环境。(--name等于-n

请注意,您也可以将环境放置在要使用的任何位置,-p /path/to/env而不是-n ENV_NAME同时创建和删除环境(如果选择)。他们不具备住在你的畅达安装。

更新,2019年1月30日:从Conda 4.6起,该conda activate命令成为激活所有平台环境的新官方方式。更改在此Anaconda博客文章中进行了描述

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


回答 1

确保您的环境未处于活动状态后,键入:

$ conda env remove --name ENVIRONMENT

After making sure your environment is not active, type:

$ conda env remove --name ENVIRONMENT

回答 2

官方文档对我有用:

conda remove --name myenv --all

或者只是conda env remove --name myenv

要验证是否已删除环境,请在您的终端窗口或Anaconda Prompt中运行:

conda info --envs

显示的环境列表不应显示已删除的环境。

您的anaconda3环境文件夹可能会在anaconda3安装文件夹中列出已删除环境的空文件夹,例如:

/opt/anaconda3/envs

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

回答 3

总共有3种方法可以实现此目的。假设您有一个名为的环境myenv

  1. conda env remove --name myenv-n是的快捷方式--name

  2. conda remove --name myenv --all

  3. 直接删除env文件夹。(不建议)

    # 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

如果您想删除环境而没有提示让您再次检查。使用的-y快捷方式--yes。(对于全局使用,请检查conda中的无提示提示

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

参考资料

  • conda env --help
  • conda remove --help

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

回答 4

您可以尝试以下操作:打开anaconda命令提示符并键入

conda remove --name myenv --all

这将删除整个环境。

进一步阅读:docs.conda.io>管理环境

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


回答 5

首先,您必须先停用环境,然后再将其删除。您可以使用以下命令删除conda环境

假设您的环境名称为“ sample_env”,则可以使用删除此环境

source deactivate    
conda remove -n sample_env --all

‘–all’将用于删除所有依赖项

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


回答 6

--prefix-p标志创建的环境必须用-p标志(not -n)删除。

例如: conda remove -p </filepath/myenvironment> --all,其中</filepath/myenvironment>用到环境的完整或相对路径代替。

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.


回答 7

我的环境名称是:test

conda remove -n test --all

My environment name is: test

conda remove -n test --all

回答 8

用于source deactivate在删除环境之前停用它,将ENV_NAME替换为您要删除的环境:

source deactivate
conda env remove -n ENV_NAME

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

回答 9

首先停用环境,然后返回基本环境。从基础上,您应该能够运行命令conda env remove -n <envname>。这会给你消息

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

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


回答 10

如果您在基地

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

通过以下方式删除env_name

conda env remove -n env_name

如果您已经在env_name环境中:

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

停用然后通过以下方式删除:

conda deactivate env_name

conda env remove -n env_name

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 env_name

conda env remove -n env_name

回答 11

这为我工作:

conda env remove --name tensorflow

This worked for me:

conda env remove --name tensorflow

回答 12

删除完整的conda环境:

康达删除–name YOUR_CONDA_ENV_NAME-全部

To remove complete conda environment :

conda remove --name YOUR_CONDA_ENV_NAME --all


回答 13

因为您只能停用活动环境,所以conda deactivate既不需要也不接受参数。错误消息在这里非常明确。

只需调用conda停用 https://github.com/conda/conda/issues/7296#issuecomment-389504269

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