There are at least three good options available today:
-
Poetry uses
pyproject.tomlandpoetry.lockfiles, much in the same way thatpackage.jsonand lock files work in the JavaScript world.This is now my preferred solution.
-
Pipenv uses
PipfileandPipfile.lock, also much like you describe the JavaScript files.
Both Poetry and Pipenv do more than just dependency management. Out of the box, they also create and maintain virtual environments for your projects.
-
pip-toolsprovidespip-compileandpip-synccommands. Here,requirements.inlists your direct dependencies, often with loose version constraints andpip-compilegenerates locked downrequirements.txtfiles from your.infiles.This used to be my preferred solution. It’s backwards-compatible (the generated
requirements.txtcan be processed bypip) and thepip-synctool ensures that the virtualenv exactly matches the locked versions, removing things that aren’t in your “lock” file.