Learn Programming, Tech & Coding · Free Online Tools

IT Question Answer
Back to Python
Python Virtual Environments Guide

Python Virtual Environments Guide

Python535 viewsBy Admin
pythonvirtualenvironments

Why Virtual Environments?

A virtual environment is an isolated Python setup for each project, so dependencies don't clash. Project A can use Django 3 while Project B uses Django 5.

Creating One with venv (Built-in)

# Create
python -m venv venv

# Activate (Mac/Linux)
source venv/bin/activate

# Activate (Windows)
venv\Scripts\activate

# Deactivate
deactivate

Installing Packages

pip install requests django
pip freeze > requirements.txt   # save dependencies
pip install -r requirements.txt # restore them elsewhere

Modern Alternatives

ToolBest for
venvBuilt-in, simple
PoetryDependency + packaging
uvExtremely fast, modern
condaData science / scientific

FAQs

Should I commit the venv folder?

No — add venv/ to .gitignore and commit requirements.txt instead.

How do I know I'm in a venv?

Your terminal prompt shows (venv). More in our Python section.