2c: Python Project and Environment Management
Pinning our package versions is a key part of reproducibility, and better than the alternatives.
We are making the Python part of a project authoritative and reproducible.
The problem we’re working around is what happens when we don’t have separate environments for different projects.
We end up with a choice between never upgrading (so we don’t break anything) or breaking things in order to upgrade.
Having separate environments for different projects allows us to have a defined set of packages and versions for each project.
This avoids the break-or-never-upgrade problem, and also makes our projects more reproducible.
pyproject.tomlpyproject.tomlModern Python projects commonly use pyproject.toml.
It can store:
pip install?pip install polars fixes the current environment.
It does not, by itself, capture what the project needs to work as intended or exactly as originally done.
pip freeze shows the packages installed in the current environment. We can use it as a terminal readout, then copy the versions we intentionally care about into pyproject.toml.
We do not need to save the whole list or copy every package in it. Be sparing: let the solver do its job.
When a project needs a package:
pyproject.toml;pip solve versions;pip freeze to see the installed versions;Open the 2c activity page.