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
How to free disk space taken up by (ana)conda?
提问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:
问题:
- In general: What is the best way to reduce the space taken up by conda?
- 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 autoremove
from Ubuntu/Debian.
- 一般而言:减少 conda 占用的空间的最佳方法是什么?
- 我如何摆脱没有环境不再使用的包?我如何修剪我的包裹?我正在寻找类似
sudo apt-get autoremove
Ubuntu/Debian 的东西。
采纳答案by Make42
Finally I got around dealing with this issue. In the end it was a couple of days work:
最后我解决了这个问题。最后是几天的工作:
- 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.yml
to save the settings of the environment from https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#exporting-the-environment-file - Check whether my projects still work with new environments created from the environment.yml.
- Use
anaconda-clean
from option B in https://docs.anaconda.com/anaconda/install/uninstalland put the created backup in a save place. - Rename the old
anaconda2
directory toanaconda2_backup
. - Install a new conda environment -
miniconda3
in my case. - Build new environments which are need for current projects from the
environment.yml
s and check whether these work. - Delete the old anaconda backups.
- 对于我所有的 Python 项目,我使用 PyCharm 并使用它检查哪个项目使用哪个环境。对于所有环境,我使用了
conda env export > environment.yml
从https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#exporting-the-environment-file保存环境设置 - 检查我的项目是否仍然适用于从 environment.yml 创建的新环境。
- 使用https://docs.anaconda.com/anaconda/install/uninstall 中的
anaconda-clean
选项 B,并将创建的备份放在保存位置。 - 将旧
anaconda2
目录重命名为anaconda2_backup
. - 安装一个新的 conda 环境 -
miniconda3
就我而言。 - 从
environment.yml
s构建当前项目所需的新环境并检查这些环境是否有效。 - 删除旧的 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
clean
Remove 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])