Interview Prep/Python for DevOps/Environments, dependencies & packaging

Why is `pip freeze > requirements.txt` not a great lock strategy?

IntermediateConceptEnvironments, dependencies & packaging
Answer

It dumps whatever happens to be installed in the current environment, including leftovers from experiments and tools like pytest or ipython, with no record of which packages you actually depend on directly. It has no hashes and no separation between prod and dev dependencies. Better: keep direct dependencies in pyproject.toml or requirements.in, compile them into a pinned, hashed lock (pip-compile --generate-hashes), and install with pip install --require-hashes -r requirements.txt.

All Python for DevOps questions Roadmap: Python for automation

More on Environments, dependencies & packaging