pythonpippython-packagingrequirements.txtpip-tools

pip-compile for setup.py's install_requires instead of requirements.txt


pip-compile enables traceability in pinning requirements inside a requirements.txt with an external requirements.in. I really like this

My question is, can we somehow do the same, but for an install_requires list inside setup.py?

In other words, if I don't have a requirements.txt but instead just a setup.py, is it possible to use pip-compile?


Solution

  • Yes, pip-tools supports pyproject.toml, setup.cfg, and setup.py configuration files from version 6.1.0 (2021-04-14).

    You should just run:

    pip-compile -o requirements.txt YOUR_CONFIG_FILE
    # where YOUR_CONFIG_FILE can be a setup.py
    # or even simpler
    pip-compile YOUR_CONFIG_FILE
    

    Take a look at the documentation:

    Requirements from pyproject.toml

    Requirements from setup.py and setup.cfg

    Changelog, verson 6.1.0 (2021-04-14)