What is Virtual Environment?What is Virtual Environment?

Python has a wide variety of modules that can be installed using the console command pip, and among them, there are many different versions of Python available.

Python versions may support different sets of tools, modules, development environments, etc. Having only one version of Python on a computer can cause many errors, for example, new versions of Python are not yet adapted to all the necessary modules, or conversely, there are no modules for a new version of Python.

To solve this problem, there is the concept of a virtual environment, which allows you to isolate the version of Python and the list of modules for a specific project.


Virtual Environment (venv) is an isolated development environment that allows developers to create an independent Python runtime and module environment for each project. This helps to avoid conflicts between different project dependencies and allows for more efficient collaboration across different development teams.

The system interpreter is the interpreter that you install on your device (i.e., on your operating system: Windows, Linux, or MacOS). Commands in the terminal work through this interpreter if you do not have a virtual environment.

How venv works?

When you create a virtual environment, you are essentially copying your system interpreter into the project folder with no additional modules loaded via pip. This creates a completely new and independent interpreter, similar to adding another Python to your computer. Once this new interpreter is activated, the required modules for the project can be loaded.

In the image, you can see separate Python interpreters. The Python version was copied from the base (system) interpreter, but additional modules were not installed in all projects. The Web Backend Project cannot use modules such as numpy and pandas because they are not installed there, while the New Project is completely empty and copied only built-in modules and the system version of the interpreter (i.e., it looks like the Python that was in your system immediately after installation, without additional pip modules).

This is a simplified explanation of how virtual environments work. In practice, the process can be a bit more complex, but you should be able to handle it without issue.


What is virtual environment (venv)?

Select the correct answer

Everything was clear?

Section 4. Chapter 1