Quiz

Virtual Environments & pip

Project A needs rich 12 and project B needs rich 13. If you install everything into one shared Python, they'll fight. A virtual environment (venv) gives each project its own private set of packages.

python -m venv .venv            # create it (once per project)
source .venv/bin/activate       # macOS / Linux
.venv\Scripts\activate          # Windows
python -m pip install rich      # installs into .venv only
python -m pip install -e .      # install YOUR project, editable
deactivate                      # leave the venv
  • Activating puts the venv's python and pip first on your PATH.
  • python -m pip makes sure you use the pip that belongs to that Python.
  • -e (editable) links to your source, so edits take effect without reinstalling.
  • pip does not edit pyproject.toml for you. You list the dependencies there yourself. Lock files or pip freeze record exact versions.
  • Never commit .venv/ to git. It's easy to rebuild.

Pip tip: Modern tools like uv do all of this very quickly, but the ideas are the same: one isolated environment per project.

You run `python -m venv .venv`, activate it, then `python -m pip install rich`. Where does `rich` end up?