且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除Conda环境

更新时间:2023-02-16 19:55:19

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

您可以使用命令

  conda env remove -n ENV_NAME 

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

请注意,在创建和删除环境时,也可以使用 -p/path/to/env 而不是 -n ENV_NAME 将环境放置在所需的任何位置.选择.他们没有可以住在您的conda安装中.

更新,2019年1月30日:从Conda 4.6起, conda activate 命令成为在所有平台上激活环境的新官方方式.在此Anaconda博客帖子中描述了这些更改 >

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?

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