Python conda:从基础/根环境中删除所有已安装的软件包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52830307/
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 20:12:10  来源:igfitidea点击:

conda: remove all installed packages from base/root environment

pythoncondaminiconda

提问by Tom Hale

TL:DR: How can I remove all installed packages from base?

TL:DR:如何从 中删除所有已安装的软件包base

I installed a bunch of machine learning packages in my baseconda environment.

我在baseconda 环境中安装了一堆机器学习包。

I've now created a mlenvironment for machine learning, and wish to reset my baseenvironment by removing all the packages installed there.

我现在已经ml为机器学习创建了一个环境,并希望base通过删除安装在那里的所有软件包来重置我的环境。

I've tried:

我试过了:

% activate base
% conda uninstall -n base --all

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

Apparently, I can't remove packages from the current environment(?!), so lets switch to my mlenvironment first:

显然,我无法从当前环境中删除包(?!),所以让我们先切换到我的ml环境:

% source activate ml
% conda uninstall -n base --all

CondaEnvironmentError: cannot remove root environment,
       add -n NAME or -p PREFIX option

Orright, I'll use -pthen...

好吧,那我就用-p...

% conda uninstall -p ~/.local/share/miniconda3 --all

CondaEnvironmentError: cannot remove root environment,
       add -n NAME or -p PREFIX option

How do I uninstall all installed packages in the baseor rootenvironment?

如何卸载baseorroot环境中所有已安装的软件包?

回答by merv

Apparently, I can't remove packages from the current environment(?!)

显然,我无法从当前环境中删除包(?!)

It's not that, but instead that you can't remove the baseenvironment, which is what the --allflag does. You can't uninstall allpackages in basebecause that's where the conda executable lives. Instead, what you want to do is uninstall all user-installed packages.

不是这样,而是您无法删除基础环境,这就是--all标志的作用。您无法卸载base中的所有软件包,因为这是 conda 可执行文件所在的位置。相反,您要做的是卸载所有用户安装的软件包。

Full Reversion (Not Recommended)

完全还原(不推荐)

One way to do this is to revert your environment back to the original state before you installed any additional packages:

一种方法是在安装任何其他软件包之前将您的环境恢复到原始状态:

# Not generally recommended!
conda install --revision 0

Be aware the multiple users have reported this breaking their Conda installation. I definitely would not run this on an installation that you have had for a long time or has many revisions.

请注意,多个用户报告说这破坏了他们的 Conda 安装。我绝对不会在您使用了很长时间或经过多次修订的安装上运行它。

Most importantly: Always review the proposed transactions in thebase env! This is where Conda lives and unfortunately the safeguards against breaking an installation are not comprehensive.

最重要的是:始终拟议交易的基础ENV!这是 Conda 居住的地方,不幸的是,防止破坏安装的保护措施并不全面。

If you really want a clean start, then export your envs to YAMLs and reinstall a fresh Miniconda.

如果你真的想要一个干净的开始,那么将你的环境导出到 YAML 并重新安装一个新的 Miniconda。

Partial Reversion

部分回复

You can also look for other previous states that might be less of a regression, but still get rid of whatever packages you think you've unnecessarily accumulated.

您还可以寻找其他以前的状态,这些状态可能不是回归,但仍然可以摆脱您认为不必要地积累的任何包。

conda list -n base -r

In the end, you'll probably want to upgrade condaright after, since it will also revert any updates to the base packages.

最后,您可能希望在conda之后立即升级,因为它还会恢复对基本软件包的任何更新。



Errors, oh my!

错误,天哪!

While the above is the correct way to revert, I encounter the error:

虽然以上是正确的还原方法,但我遇到了错误:

CondaRevisionError: Cannot revert to 0, since ::contextlib2-0.5.3-py35_0 is not in repodata.

CondaRevisionError:无法恢复为 0,因为 ::contextlib2-0.5.3-py35_0 不在 repodata 中。

As an aside, this sort of worries me because it seems to indicate that the state of my Conda environment from two years ago is no longer reproducible from the state of the upstream channels.

顺便说一句,这种担心让我担心,因为它似乎表明两年前我的 Conda 环境的状态不再可以从上游通道的状态重现。

Under this situtation, I don't know a clean way to solve this other than comparing all the revision 0 packages to your current install and then uninstalling the difference. But again, a clean install of Miniconda seems like a nicer solution.

在这种情况下,除了将所有修订版 0 包与您当前的安装进行比较然后卸载差异之外,我不知道一种干净的方法来解决这个问题。但同样,全新安装 Miniconda 似乎是一个更好的解决方案。

Generally, I've found that treating envs as immutable and installing as little as possible in baseis the safest and most reliable way to use Conda.

通常,我发现将 envs 视为不可变的并在base 中尽可能少地安装是使用 Conda 的最安全、最可靠的方法。

回答by Aaayue

I had the same problem as you did, this is what I did:

我遇到了和你一样的问题,这就是我所做的:

  1. backup my conda-env:

    i. activate the env i want keep, such as 'ml'

    ii. type conda-env export > /path/to/save/file/environment.yml

  2. activate baseand revert base env to initial: type conda install --revision 0, this should take some time...(this command did not revert ALL my envs, just the BASE env)

  3. load your .yml file: type conda env create -f /path/to/save/file/environment.yml

  1. 备份我的 conda-env:

    一世。激活我想要保留的环境,例如“ml”

    ii. 类型conda-env export > /path/to/save/file/environment.yml

  2. 激活base并将基础环境恢复为初始:键入conda install --revision 0,这应该需要一些时间......(这个命令没有恢复我所有的环境,只是基础环境)

  3. 加载您的 .yml 文件:键入 conda env create -f /path/to/save/file/environment.yml

回答by user3805442

i solve this by doing this

我通过这样做来解决这个问题

python3 -m ipykernel install --user

python3 -m ipykernel install --user