conda: remove all installed packages from base/root environment

跟風遠走 提交于 2019-12-03 05:03:23

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

It's not that, but instead that you can't remove the base environment, which is what the --all flag does. You can't uninstall all packages in base because that's where the conda executable lives. Instead, what you want to do is uninstall all user-installed packages. One way to do this is to revert your environment back to the original state before you installed any user packages:

> conda install --revision 0

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 conda right after, since it will also revert any updates to the base packages.


Errors, oh my!

While the above is the really right way to go, I encounter the error:

CondaRevisionError: Cannot revert to 0, since ::contextlib2-0.5.3-py35_0 is not in 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. I've been working under the assumption that this type of reproducibility is built-in.

Anyway, 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.

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 base and 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

i solve this by doing this

python3 -m ipykernel install --user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!