Do Virtual Environment Waste Disk Space? How to overcome that? (2024)

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.

Do Virtual Environment Waste Disk Space? How to overcome that? (3)

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

Do Virtual Environment Waste Disk Space? How to overcome that? (4)

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇

🚀Developers: Learn and grow by keeping up with what matters, JOIN FAUN.

Do Virtual Environment Waste Disk Space? How to overcome that? (2024)
Top Articles
Latest Posts
Article information

Author: Rubie Ullrich

Last Updated:

Views: 5812

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Rubie Ullrich

Birthday: 1998-02-02

Address: 743 Stoltenberg Center, Genovevaville, NJ 59925-3119

Phone: +2202978377583

Job: Administration Engineer

Hobby: Surfing, Sailing, Listening to music, Web surfing, Kitesurfing, Geocaching, Backpacking

Introduction: My name is Rubie Ullrich, I am a enthusiastic, perfect, tender, vivacious, talented, famous, delightful person who loves writing and wants to share my knowledge and understanding with you.