When to use pip requirements file versus install_requires in setup.py?

前端 未结 4 542
谎友^
谎友^ 2020-12-12 11:07

I\'m using pip with virtualenv to package and install some Python libraries.

I\'d imagine what I\'m doing is a pretty common scenario. I\'m the maintainer on seve

4条回答
  •  生来不讨喜
    2020-12-12 11:17

    The Python Packaging User Guide has a page about this topic, I highly recommend you read it:

    • install_requires vs Requirements files

    Summary:

    install_requires is there to list the dependencies of the package that absolutely must be installed for the package to work. It is not meant to pin the dependencies to specific versions, but ranges are accepted, for example install_requires=['django>=1.8']. install_requires is observed by pip install name-on-pypi and other tools.

    requirements.txt is just a text file, that you can choose to run pip install -r requirements.txt against. It's meant to have versions of all dependencies and subdependencies pinned, like this: django==1.8.1. You can create one using pip freeze > requirements.txt. (Some services, like Heroku, automatically run pip install -r requirements.txt for you.) pip install name-on-pypi does not look at requirements.txt, only at install_requires.

提交回复
热议问题