`requirements.txt` vs `pyproject.toml`: what goes where?
IntermediateConceptEnvironments, dependencies & packaging
Answer
pyproject.toml(PEP 621) declares the project: name, version, Python requirement, abstract dependencies with ranges (boto3>=1.35), optional extras, entry points, and tool config (ruff, mypy, pytest).- A lock file or a fully pinned
requirements.txtrecords the exact resolved versions of everything, including transitive dependencies, for reproducible installs.
Libraries publish ranges; applications and Docker images install from a lock. We generate the lock with pip-compile (pip-tools), uv pip compile or uv lock, and commit it.
More on Environments, dependencies & packaging
What is a virtual environment and why do we always use one?BeginnerWhat does `error: externally-managed-environment` mean?BeginnerWhy is `pip freeze > requirements.txt` not a great lock strategy?IntermediateWhat do version specifiers like `~=`, `==`, `>=,<` mean?BeginnerWhat are `pipx` and `uv`, and when do you use them?IntermediateHow do you manage multiple Python versions on one machine?Intermediate