What is it? Edit

A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated python virtual environments for them. It is a very important tool for developers.

Why use it? Edit

Imagine for example that you are working on two different web based python projects and one of them uses Django 1.9 and the other uses Django 1.10. In such situations a virtual environment can be very useful to maintain dependencies of both projects.

When/where use it? Edit

By default, every project on your system will use the same directories to store and retrieve site packages (third party libraries). This is important because (say in the case of the above example) in our two projects we have two versions of Django. This is a problem for Python since it can't differentiate between versions in the "site-packages" directory. so both v1.9 and v1.10 would reside in the same directory with the same name. This is where virtual environments come in.

To solve this problem we just need to create two separate virtual environments for both projects.

A virtual environment should be used whenever you are working on a Python based project. It is generally speaking, good to have one new virtual environment for every Python based project you are working on. So the dependencies of every project are isolated from the system and each-other.

How does it work? Edit

We use a module named virtualenv which is a tool to create isolated Python environments. virtualenv creates a folder which contains all the necessary executables to use the package that a Python project would need.

References Edit

Python Virtual Environment Introduction - Geeks for Geeks

Community content is available under CC-BY-SA unless otherwise noted.