conda环境的磁盘使用情况似乎比检查目录属性时要多得多?

问题描述 投票:1回答:1

首先,我是虚拟环境的新手,并且我不是来自软件背景的(英语也不是我的母语,所以请您不要打扰)。我敢肯定,conda环境已经过优化,不会重复使用磁盘上的软件包,而是使用了链接。但是,当检查使用的硬盘空间时(在Linux Mint上,通过右键单击->属性),它看起来确实很高:超过2 GB(env具有python,numpy和pandas)。

有人能告诉我(或指出方向)这是如何工作的吗?

conda diskspace
1个回答
0
投票

2 GB对于该软件包列表来说似乎太高了。我刚刚做了测试。在Linux上,这样的环境占用1.2 GB。在Mac上,仅需要271 MB。 (我不完全确定是什么导致了两者之间的差异,但这可能与不同的文件系统有关。)

您要检查单个环境的大小,还是要检查整个anaconda目录树的大小?

关于conda中的磁盘保存技巧:是的,conda使用硬链接(如果可能)以避免在磁盘上复制文件。这有助于节省磁盘空间,因为否则将在多个环境中以及conda程序包缓存(pkgs)中复制相同的文件。不幸的是,由于技术原因,conda无法创建指向某些文件的硬链接,因此它必须复制这些文件。

du工具可以告诉您特定目录(或目录列表)占用了多少磁盘空间。它知道硬链接,因此如果同一文件由于硬链接而出现两次,则可以避免重复计算文件大小。 (我不知道Linux Mint中的“属性”菜单项的行为是否相同。)

例如,我将创建两个相同的conda环境并独立检查其磁盘使用情况:

$ conda create -n test-1 -y python numpy pandas
$ conda create -n test-2 -y python numpy pandas

$ du -h -s $(conda info --base)/envs/test-1
1.2G    /opt/miniconda/envs/test-1

$ du -h -s $(conda info --base)/envs/test-2
1.2G    /opt/miniconda/envs/test-2

但是如果我要求du考虑它们[[同时,它会注意到test-2中的某些文件已经在test-1中看到,因此将不再计算它们的大小:

$ du -h -s $(conda info --base)/envs/test-? 1.2G /opt/miniconda/envs/test-1 268M /opt/miniconda/envs/test-2
如果您想知道哪些文件是硬链接的,请查看ls -l的输出:

$ ls -l $(conda info --base)/envs/test-1/lib/libz.so.1.2.11 -rwxrwxr-x 15 bergs flyem 109272 Sep 9 2019 /opt/miniconda/envs/test-1/lib/libz.so.1.2.11 ^ `-- This file has 15 different names, i.e. it can be found in 15 different places on disk, due to hard-links. $ ls -l $(conda info --base)/envs/test-1/lib/libpython3.8.so.1.0 -rwxrwxr-x 1 bergs flyemdev 14786920 Jun 16 12:44 /opt/miniconda/envs/test-1/lib/libpython3.8.so.1.0 ^ `-- This file has only 1 name on disk, i.e. there are no other hard-links to this file.

© www.soinside.com 2019 - 2024. All rights reserved.