Open this lesson in your favourite AI. It'll walk you through the why, explain the demo, and quiz you on the try-it list.
A virtualenv is a Python install isolated to one project — install Flask in venv-A and it doesn't bleed into venv-B. This was solved 15 years ago but the tools have always been clunky (virtualenv, venv, pipenv, poetry). uv collapses the whole stack: uv venv creates an env in 50 ms, uv pip install resolves and installs deps 10–100× faster than pip, and uv pip compile produces a deterministic lockfile. If you're starting a new project in 2026, this is the path. (pip and venv still work; uv is just better.)
A virtualenv is an isolated copy of the Python interpreter with its own site-packages directory, which means installing a package into one project's venv never collides with another project's dependencies. uv venv creates one in about 50 ms — far faster than python -m venv — and uv pip install resolves and installs the full dependency graph, including transitive deps, in a single pass. Freezing the result to requirements.txt (or using uv lock) records the exact set of hashed wheel URLs needed to reproduce the environment byte-for-byte on any machine six months from now.
uv venv, look inside .venv/. Note it's just a directory — no global state.uv pip install fastapi and time it (time uv pip install fastapi). Then nuke .venv and reinstall — both should be sub-second after the first download.uv pip freeze > requirements.txt and read it. This is your reproducibility contract.uv pip install --no-deps fastapi. Note that fastapi alone won't run without its deps — --no-deps is for surgical updates.Use these three in order. Each builds on the one before.
In one paragraph, explain what a Python virtualenv actually is, and why every project should have one.
How does activating a venv change things — what does `source .venv/bin/activate` actually do to PATH and `sys.path`?
What's the right way to handle dev-only deps (pytest, mypy, ruff) so they don't ship to production? Compare `requirements-dev.txt`, optional dependency groups in pyproject.toml, and uv's `--dev` flag.
# create a venv (in .venv/ by default):
$ uv venv
Using Python 3.12.2
Creating virtualenv at: .venv
$ source .venv/bin/activate # or run commands via `uv run`
# install:
$ uv pip install fastapi httpx
Resolved 12 packages in 87ms
Downloaded 12 packages in 234ms
Installed 12 packages in 56ms
# inspect:
$ uv pip list
fastapi 0.110.0
httpx 0.27.0
...
# freeze for reproducibility:
$ uv pip freeze > requirements.txt
$ uv pip compile requirements.in -o requirements.txt # PEP 621 way
# nuke and recreate:
$ rm -rf .venv && uv venv && uv pip install -r requirements.txtpython3 main.py