Python Virtual Environments — venv, pip & Dependencies
Set up Python virtual environments with venv. Install packages, requirements.txt, and project isolation.
Python virtual environmentpython venvpip install
Python venv and pip Workflow
Virtual environments isolate project dependencies so Project A's Django version doesn't break Project B. Every Python project should use one.
Why Python virtual environment Matters
Without venv, global package installs cause version conflicts that are painful to debug across team machines.
One venv per project, requirements.txt committed to git, never pip install globally for application dependencies.
Python virtual environment — Key Ideas You Must Know
- python -m venv .venv
- Activate: source .venv/bin/activate
- pip install package
- pip freeze > requirements.txt
- Never install globally for projects
How to Use Python virtual environment Step by Step
- Create venv
- Activate
- pip install dependencies
- Freeze requirements.txt
- Add .venv to .gitignore
Practice Python virtual environment with Free Lessons
Set up venv while following the Python intro tutorial on Sturdee.
Tip: Free interactive lesson: /tutorials/python — practice Python virtual environment with runnable code on Sturdee.
Python Virtual Environments — FAQ
Frequently Asked Questions
venv vs conda?+
venv is built-in and enough for most web projects. Conda shines for data science.
Continue learning interactively
Free tutorial: /tutorials/python →