Python 如何释放(ana)conda占用的磁盘空间?

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

How to free disk space taken up by (ana)conda?

pythonanacondaconda

提问by Make42

I am using the conda package manager - a lot. By now I have quite a few environments and a lot of downloaded packages taking a lot of space on my SSD. An obvious path to free some of that space is to use the command

我正在使用 conda 包管理器 - 很多。到目前为止,我有相当多的环境和大量下载的软件包,它们占用了我的 SSD 上的大量空间。释放一些空间的一个明显途径是使用命令

conda env export > environment.yml

from https://conda.io/docs/user-guide/tasks/manage-environments.html#exporting-the-environment-fileto export which packages my old, inactive projects use(d) and then delete these environments. As far as I understand, this should free some of the space in anaconda2/envs/, but not in anaconda2/pkgs/. How do I get rid of these packages? Also, I suspect that there might be quite a few packages still sitting around, to which no environment is linking to - could that happen?

https://conda.io/docs/user-guide/tasks/manage-environments.html#exporting-the-environment-file导出我旧的非活动项目使用的包(d)然后删除这些环境。据我了解,这应该释放一些空间anaconda2/envs/,但不是在anaconda2/pkgs/。我如何摆脱这些包?另外,我怀疑可能还有很多包仍然存在,没有环境链接到这些包 - 这会发生吗?

Questions:

问题:

  1. In general: What is the best way to reduce the space taken up by conda?
  2. How do I get rid of packages that no environment is using anymore? How do I prune my packages? I am searching for something like sudo apt-get autoremovefrom Ubuntu/Debian.
  1. 一般而言:减少 conda 占用的空间的最佳方法是什么?
  2. 我如何摆脱没有环境不再使用的包?我如何修剪我的包裹?我正在寻找类似sudo apt-get autoremoveUbuntu/Debian 的东西。

采纳答案by Make42

Finally I got around dealing with this issue. In the end it was a couple of days work:

最后我解决了这个问题。最后是几天的工作:

  1. For all my Python projects I use PyCharm and with it I checked which project uses which environment. For all environments I used the conda env export > environment.ymlto save the settings of the environment from https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#exporting-the-environment-file
  2. Check whether my projects still work with new environments created from the environment.yml.
  3. Use anaconda-cleanfrom option B in https://docs.anaconda.com/anaconda/install/uninstalland put the created backup in a save place.
  4. Rename the old anaconda2directory to anaconda2_backup.
  5. Install a new conda environment - miniconda3in my case.
  6. Build new environments which are need for current projects from the environment.ymls and check whether these work.
  7. Delete the old anaconda backups.
  1. 对于我所有的 Python 项目,我使用 PyCharm 并使用它检查哪个项目使用哪个环境。对于所有环境,我使用了conda env export > environment.ymlhttps://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#exporting-the-environment-file保存环境设置
  2. 检查我的项目是否仍然适用于从 environment.yml 创建的新环境。
  3. 使用https://docs.anaconda.com/anaconda/install/uninstall 中的anaconda-clean选项 B,并将创建的备份放在保存位置。
  4. 将旧anaconda2目录重命名为anaconda2_backup.
  5. 安装一个新的 conda 环境 -miniconda3就我而言。
  6. environment.ymls构建当前项目所需的新环境并检查这些环境是否有效。
  7. 删除旧的 anaconda 备份。

Finally I also reduced my logical volume with https://blog.shadypixel.com/how-to-shrink-an-lvm-volume-safely/but this is only for Linux users using LVMs.

最后,我还使用https://blog.shadypixel.com/how-to-shrink-an-lvm-volume-safely/减少了我的逻辑卷,但这仅适用于使用 LVM 的 Linux 用户。

This way I was able to free 20 to 30 GB of space.

通过这种方式,我能够释放 20 到 30 GB 的空间。

回答by Mike Müller

You can free some space with:

您可以通过以下方式释放一些空间:

conda clean --all

cleanRemove unused packages and caches.

clean删除未使用的包和缓存。

Conda already use symlinks when possible for packages. So, not much to improve here, I guess.

Conda 已经在可能的情况下为包使用了符号链接。所以,我想,这里没有太多需要改进的地方。

Ok, thanks, but I would like to know "not for a specific environment, but in general" - for all environments.

好的,谢谢,但我想知道“不是针对特定环境,而是针对所有环境”。

You can list all packages in all envs with a few lines of Python:

您可以使用几行 Python 列出所有环境中的所有包:

import os
import subprocess
for env in os.listdir('/Users/me/miniconda3/envs'):
    subprocess.call(['conda', 'list', '-n', env])