How to create a Python virtual environment step-by-step

Yesi Days
3 min readMay 30, 2023

When you’re first introduced to Python, the concept of a virtual environment might not be the first thing you encounter. However, as you dive deeper into Python development, especially when dealing with multiple projects, understanding and using virtual environments becomes essential.

What is a Python virtual environment?

A Python virtual environment is an isolated environment where you can install packages and dependencies that are separate from those installed in other virtual environments and your system’s default Python environment. Each virtual environment has its own Python binary and can have its own unique set of installed Python packages in its site directories.

In essence, it’s like having a container solely dedicated to your Python project, where you have everything you need and nothing you don’t, without interfering with the other containers (or global environment).

Why Do We Need?

Let’s consider a scenario: You are working on two web-based Python projects, one requires Django 2.0, and the other needs Django 3.0. If you install both versions of Django in the global environment, there will be a conflict. This is where virtual environments come to the rescue.

By using a separate virtual environment for each project, you can install the appropriate version of Django (or any other package) in each one, and the two projects will remain independent…

--

--

Yesi Days

GDE Machine Learning | Data Scientist | PhD in Artificial Intelligence | Content creator | Ex-backend