Creating virtual environment Python – You know that moment when youβre working on multiple Python projects, and suddenly one project breaks because another updated a package? Yeah, Iβve been there too.Β
Thatβs exactly why I started using virtual environmentsβand honestly, it was one of the best coding decisions I ever made.
Table Of Content
- What is a Virtual Environment in Python?
- Why You Should Use a Virtual Environment
- Step-by-Step: How to Set Up a Virtual Environment in Python
- Step 1: Check Your Python Version
- Step 2: Install venv (if itβs not already installed)
- Step 3: Create Your Virtual Environment
- Step 4: Activate the Virtual Environment
- Step 5: Install Packages
- Step 6: Deactivate the Environment
- Step 7: Save Dependencies
- Real-Life Example: How It Saved My Project
- Common Mistakes Beginners Make
- Final Thoughts
- Related Reads
So, in this blog, Iβm going to show you exactly how to set up a virtual environment in Python, explain why itβs so useful, and share a few lessons Iβve learned the hard way.
What is a Virtual Environment in Python?

Before we get into creating virtual environment Python, letβs talk about what it actually is.
A virtual environment in Python is like having your own private workspace for each project.
It lets you install and manage dependencies independentlyβso one project doesnβt mess with another.
Think of it as having separate toolkits for each job. One project might use Django 3.2, another Django 4.0βand thatβs totally fine. No conflicts.
If youβve ever installed a package globally and later regretted it, youβll understand why creating virtual environment Python is such a game-changer.
Why You Should Use a Virtual Environment
Hereβs the truth: skipping virtual environments might not break your code today, but it will bite you later.
Hereβs why itβs so useful:
-
π§© Isolation: Keeps dependencies separate for each project.
-
π Version control: You can use different package versions without conflicts.
-
πΌ Team consistency: Everyone on your team can use the same setup.
-
π Cleaner system: No more cluttered global installations.
-
π§° Reproducibility: You can recreate the same environment anywhereβlocally, on servers, or in the cloud.
When I started working on multiple data science projects, I learned the hard way that installing everything globally quickly becomes a nightmare. Using creating virtual environment Python fixed that instantly.

Step-by-Step: How to Set Up a Virtual Environment in Python
Alright, letβs get practical. Hereβs how I personally do itβstep by step.
Step 1: Check Your Python Version
First, make sure Python is installed. Open your terminal and type:
python --version
If you get something like Python 3.10.6, youβre good to go.
Step 2: Install venv (if itβs not already installed)

From Python 3.3 onwards, venv comes pre-installed.
But if youβre missing it, you can install it like this:
pip install virtualenv
Step 3: Create Your Virtual Environment
Now for the fun partβcreating virtual environment Python!
Navigate to your project folder and run:
python -m venv myenv
This creates a new folder called myenv, which holds all the environment data, packages, and configurations.
Step 4: Activate the Virtual Environment
This step depends on your operating system:
For Windows:
myenv\Scripts\activate
For macOS/Linux:
source myenv/bin/activate
Once activated, youβll notice your terminal now shows (myenv) at the start. Thatβs your confirmation youβre inside your Python virtual environment.
Step 5: Install Packages

Now, install your project dependencies within this environment.
For example:
pip install requests
Everything stays isolated inside your virtual environment.
Try running your projectβitβll use only the packages installed inside this environment, not your global system.
Step 6: Deactivate the Environment
When youβre done, just type:
deactivate
Youβre back to your global Python.
Step 7: Save Dependencies

To make sure others can use your same setup, freeze your dependencies:
pip freeze > requirements.txt
This creates a file listing every package and version. Later, you (or anyone else) can recreate it with:
pip install -r requirements.txt
This is how I share my environment setup with teammatesβit keeps everyone in sync.
Real-Life Example: How It Saved My Project
A few months back, I was working on a machine learning project using TensorFlow 2.10. Meanwhile, another project required TensorFlow 2.8.
When I installed the older version globally, it completely broke my first project.
Thatβs when I realized: I needed to start creating virtual environment Python for each project.
Once I did, everything worked perfectly. No conflicts, no broken imports, no wasted weekends.
Common Mistakes Beginners Make

Letβs be honestβwe all mess up the first few times. Here are a few common mistakes Iβve seen (and made):
-
β Forgetting to activate the virtual environment before installing packages.
-
β Installing dependencies globally by accident.
-
β Deleting the
myenvfolder without freezingrequirements.txt. -
β Confusing
virtualenvandvenv.
But donβt worryβafter a few tries, creating virtual environment Python will feel like second nature.
Official Python Docs on venv β a must-read for understanding the core concept.
Final Thoughts
If you take one thing away from this article, let it be this:
Always use a virtual environment for every Python project.
It might seem like an extra step at first, but itβll save you hours of debugging later.
Once you get comfortable with creating virtual environment Python, youβll never go back.
So go aheadβcreate one right now, play around, and experience the difference.
Kaashiv Infotech Offers,Β Full Stack Python Course,Β Python Course,Β Python InternshipΒ & More, Visit Our WebsiteΒ www.kaashivinfotech.com.

