Published in · 2 min read · Jun 1, 2022
--
A virtual environment is a Python environment such that the Python interpreter, libraries, and scripts installed into it are isolated from those installed in other virtual environments, and (by default) any libraries installed in a “system” Python, i.e., one which is installed as part of your operating system.
Support me by hitting the Follow button, to help me write more articles and guides.
Mmm, virtual environments are somehow a waste of disk space because they are meant to create isolated environments that have -almost- no dependencies outside themselves.
E.g. if you have venvA and venvB, both can be using the same version of pckgX but, none of them will share it with the other and you will have the same pckgX installed in two different environments. However this is not an awful drawback, as in most cases you use python environments to have different versions of the same package in your machine and use them interchangeably, or that is why I use virtual environments.
It makes you comfortable when you modify or delete packages in your virtual environment with no worries that you may damage other ones.
However, we can overcome this by using caches and other methods:
pip
- In pip, we can cache downloads in
~/.pip/cache
so it won't need to download them again next time by adding the following to$HOME/.pip/pip.conf
:
[global]
download_cache = ~/.pip/cache
Conda
- In conda, you can use a shared package cache by creating a directory on your system where the shared users have read and write access.
- Then, for each user who will have access, edit the
.condarc
file found in their home directory with the following entry, specifying the full path to that shared directory:
pkgs_dirs:
- /path/to/shared_directory
Windows — C:\Users\username.condarc
macOS and Linux — /home/username/.condarc
- Verify the package cache by running
conda info
.
Hope this article was beneficial to you. Don’t forget to support me by hitting the Follow button, to help me write more articles and guides