9

If I have two separate Anaconda Environments, and am installing two packages that are the same in each environment, do they install twice, and take up twice the storage?

i.e.

conda create --name myenv1

conda create --name myenv2

conda activate myenv1

conda install matplotlib

deactivate

conda activate myenv2

conda install matplotlib
john stamos
  • 1,054
  • 5
  • 17
  • 36
  • Possible duplicate of [Why are packages installed rather than just linked to a specific environment?](https://stackoverflow.com/questions/55566419/why-are-packages-installed-rather-than-just-linked-to-a-specific-environment) – merv Aug 29 '19 at 22:23

1 Answers1

11

This was a question I had wondered about myself. No it doesn't take up twice the storage. I'm using conda version 4.7.10 in a new ubuntu 18.04 container, but you can try it with your conda version and verify the results.

Environments by default are created in the envs folder under the directory you installed anaconda in. For me that is $HOME/anaconda3. After each install you want to run du -sh $HOME/anaconda3/envs to see a summary of disk space used in human readable format.

$ du -sh $HOME/anaconda3/envs
4.0K    /root/anaconda3/envs

$ conda create --name myenv1 -y
$ conda create --name myenv2 -y
$ conda install matplotlib -n myenv1 -y

$ du -sh $HOME/anaconda3/envs
338M    /root/anaconda3/envs


$ conda install matplotlib -n myenv2 -y

$ du -sh $HOME/anaconda3/envs
357M    /root/anaconda3/envs

19M more was used, but not double.

Now the question is how do they avoid doubling the space, looking and the envs directory, I don't see any symlinks anywhere. So I looked at some files under myenv2:

$ ls -lh /root/anaconda3/envs/myenv2/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSans-Bold.ttf
-rw-rw-r--. 3 root root 688K Jul  1 06:19 /root/anaconda3/envs/myenv2/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSans-Bold.ttf

The '3' after the permissions and before the file and group owner is the number of hard-links associated with a file. Normally a file has only one. Each environment must create another hard-link to the same file.

William D. Irons
  • 2,244
  • 1
  • 18
  • 19
  • 1
    Wow, using hard link is really a better choice than symlinks. – Sraw Aug 29 '19 at 22:08
  • Great information. If we had the same package of different versions, would that be separate installs? I would think so... Even in the same environment, if you have 2 versions of a package installed that will double the storage (assuming the package versions are the same size). – john stamos Sep 04 '19 at 21:50