Python Tutorial 0/52 lessons ~6 min read Lesson 31
Virtual Environments
Virtual environments isolate per-project dependencies — non-negotiable for any real Python work.
Course progress0%
Focus
9 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
Virtual environments isolate per-project dependencies — non-negotiable for any real Python work.
Understanding the topic
Core concepts to understand:
python -m venv .venvcreates one.source .venv/bin/activateuses it.uvandpoetryare modern wrappers.condafor data science with non-Python deps.
Syntax reference
Visual flow / code:
bash
# Built-in venvpython -m venv .venvsource .venv/bin/activatepip install requests fastapi# uv (super-fast, modern)uv venvuv pip install fastapi# Poetrypoetry initpoetry add fastapipoetry shell
Execution workflow
1Virtual Environments Workflow
1 / 4Step 1
python -m venv .venv creates one.
Apply this step while implementing virtual environments in real code.
Real-world use
uv (from Astral, makers of Ruff) is 10-100× faster than pip and is rapidly becoming the new standard.
Best practices
- One venv per project.
- Commit
requirements.txtorpoetry.lock. - Try uv for speed.
Common mistakes
- Installing globally with sudo pip — corrupts system Python.
Hands-on exercise
Interview preparation — practice these questions:
- venv vs conda?
- What does pip install -e do?
- Why isolate dependencies?
Summary
In summary: Always activate a venv. uv is the new fast standard.
Ready to mark this lesson complete?Track your journey across the entire course.