pip, requirements, and Virtual Environments
Scenario: Installing one project's package upgrade breaks another project.
New words, in plain English
- pip - Python's package installer
- Dependency - another package a project needs
- Virtual environment - an isolated Python and package location for one project
- requirements.txt - a reproducible list of dependency versions
Create with python3 -m venv .venv, activate it, then use python -m pip install .... Record deliberate pinned dependencies. Modern projects may use pyproject.toml, but requirements files remain common in automation.
Analogy: A Python program is like a clear set of instructions for a careful helper: names label things, indentation groups steps, and errors explain where the helper became confused.
A small, real example
python3 -m venv .venv
source .venv/bin/activate
python -m pip install pytest==8.3.3
python -m pip freeze > requirements.txt
Tip: Do not commit .venv; commit dependency declarations.
Goal: Practice this idea in the py-venv-requirements challenge at/labs/python. Fix the broken program, run it yourself, then usecheckto prove the real end state.