Virtual Environments
Give every project its own isolated Python + packages with venv — no more version conflicts between projects.
"A virtual environment is a private Python installation just for one project. Project A can use Flask 2.0 while Project B uses Flask 3.0, and they never interfere."
— ShurAIThe Problem: Global Package Conflicts
Without virtual environments, all projects share the same Python installation. This causes conflicts:
django==3.2django==5.0Virtual environments solve this by giving each project its own isolated Python + packages:
requests==2.28.0
Only what A needs
numpy==1.26.0
Only what B needs
Creating and Using a Virtual Environment
The whole workflow in four steps:
python -m venv venv
# Creates a folder called 'venv' in your project directory
# Windows:
venv\Scriptsctivate
# Mac / Linux:
source venv/bin/activate
# Your prompt changes to show (venv) at the start
# (venv) $ _
(venv) $ pip install requests pandas flask
(venv) $ deactivate
# Back to your global Python
$
The Complete Project Workflow
mkdir my-project && cd my-project — create project folderpython -m venv venv — create virtual environmentsource venv/bin/activate — activate itpip install ... — install what you needpip freeze > requirements.txt — save dependenciesvenv/ to .gitignore — don’t commit the venv folderThe venv/ folder is large and machine-specific. Always add it to .gitignore. Your requirements.txt is what you share — others recreate the venv from it using pip install -r requirements.txt.
Quick Recap — venv Cheat Sheet
python -m venv venv # create
source venv/bin/activate # activate (Mac/Linux)
venv\Scriptsctivate # activate (Windows)
pip install <package> # install inside venv
pip freeze > requirements.txt # save list
deactivate # exit venv
"Rule: every project gets its own venv. No exceptions. It takes 10 seconds to set up and saves hours of 'why is this suddenly broken' debugging later."
— ShurAI🧠 Quiz — Q1
What is the main problem that virtual environments solve?
🧠 Quiz — Q2
What command creates a virtual environment called venv in your current folder?
🧠 Quiz — Q3
How do you know a virtual environment is currently active?
🧠 Quiz — Q4
Why should you add venv/ to .gitignore?