Python 删除 Conda 环境

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49127834/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 18:59:28  来源:igfitidea点击:

Removing Conda environment

pythonjupyterconda

提问by Renato Damas

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 创建的某个环境。我怎样才能做到这一点?假设我有一个活跃的 testenv 环境。我按照文档尝试使用:

$ 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?

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

回答by holdenweb

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.

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

You can use the command

你可以使用命令

conda env remove -n ENV_NAME

to remove the environment with that name. (--nameis equivalent to -n)

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

Note that you can also place environments anywhere you want using -p /path/to/envinstead of -n ENV_NAMEwhen both creating and deleting environments, if you choose. They don't haveto live in your conda installation.

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

UPDATE, 30 Jan 2019: From Conda 4.6 onwards the conda activatecommand becomes the new official way to activate an environment across all platforms. The changes are described in this Anaconda blog post

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

回答by Renato Damas

After making sure your environment is not active, type:

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

$ conda env remove --name ENVIRONMENT

回答by Harvey

Official documentationway worked for me:

官方文档方式对我有用:

conda remove --name myenv --all

Or just conda env remove --name myenv.

或者只是conda env remove --name myenv.

To verify that the environment was removed, in your terminal window or an Anaconda Prompt, run:

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

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:

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

/opt/anaconda3/envs

回答by Simba

There're 3 ways to achieve this in total. Assuming you have a environment named myenv,

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

  1. conda env remove --name myenv, -nis 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
    
  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
    


If you wanna delete the environment without a promptto let you check again. Use -y, shortcut for --yes. (For global use check silent prompt in conda)

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

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

References

参考

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

回答by srilekha palepu - Intel

First you have to deactivate your environment before removing it. You can remove conda environment by using the following command

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

Suppose your environment name is "sample_env" , you can remove this environment by using

假设您的环境名称是 "sample_env" ,您可以使用

source deactivate    
conda remove -n sample_env --all

'--all' will be used to remove all the dependencies

'--all' 将用于删除所有依赖项

回答by Muhamad Mohsin

You may try the following: Open anaconda command prompt and type

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

conda remove --name myenv --all

This will remove the entire environment.

这将删除整个环境。

Further reading: docs.conda.io > Manage Environments

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

回答by Chris Keefe

Environments created with the --prefixor -pflag must be removed with the -pflag (not-n).

使用--prefixor-p标志创建的环境必须使用-p标志(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 remove -p </filepath/myenvironment> --all,其中</filepath/myenvironment>被替换为环境的完整或相对路径。

回答by CodeUrLife

My environment name is: test

我的环境名称是:test

conda remove -n test --all

回答by Jason

Use source deactivateto deactivate the environment before removing it, replace ENV_NAME with the environment you wish to remove:

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

source deactivate
conda env remove -n ENV_NAME

回答by Srini

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

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

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

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