|
| 1 | +:orphan: |
| 2 | + |
1 | 3 | .. _`install_requires vs requirements files`: |
2 | 4 |
|
3 | 5 | ====================================== |
4 | 6 | install_requires vs requirements files |
5 | 7 | ====================================== |
6 | 8 |
|
| 9 | +For documentation on these topics, see: |
7 | 10 |
|
8 | | -install_requires |
9 | | ----------------- |
10 | | - |
11 | | -``install_requires`` is a :ref:`setuptools` :file:`setup.py` keyword that |
12 | | -should be used to specify what a project **minimally** needs to run correctly. |
13 | | -When the project is installed by :ref:`pip`, this is the specification that is |
14 | | -used to install its dependencies. |
15 | | - |
16 | | -For example, if the project requires A and B, your ``install_requires`` would be |
17 | | -like so: |
18 | | - |
19 | | -:: |
20 | | - |
21 | | - install_requires=[ |
22 | | - 'A', |
23 | | - 'B' |
24 | | - ] |
25 | | - |
26 | | -Additionally, it's best practice to indicate any known lower or upper bounds. |
27 | | - |
28 | | -For example, it may be known, that your project requires at least v1 of 'A', and |
29 | | -v2 of 'B', so it would be like so: |
30 | | - |
31 | | -:: |
32 | | - |
33 | | - install_requires=[ |
34 | | - 'A>=1', |
35 | | - 'B>=2' |
36 | | - ] |
37 | | - |
38 | | -It may also be known that project 'A' introduced a change in its v2 |
39 | | -that breaks the compatibility of your project with v2 of 'A' and later, |
40 | | -so it makes sense to not allow v2: |
41 | | - |
42 | | -:: |
43 | | - |
44 | | - install_requires=[ |
45 | | - 'A>=1,<2', |
46 | | - 'B>=2' |
47 | | - ] |
48 | | - |
49 | | -It is not considered best practice to use ``install_requires`` to pin |
50 | | -dependencies to specific versions, or to specify sub-dependencies |
51 | | -(i.e. dependencies of your dependencies). This is overly-restrictive, and |
52 | | -prevents the user from gaining the benefit of dependency upgrades. |
53 | | - |
54 | | -Lastly, it's important to understand that ``install_requires`` is a listing of |
55 | | -"Abstract" requirements, i.e just names and version restrictions that don't |
56 | | -determine where the dependencies will be fulfilled from (i.e. from what |
57 | | -index or source). The where (i.e. how they are to be made "Concrete") is to |
58 | | -be determined at install time using :ref:`pip` options. [1]_ |
59 | | - |
60 | | - |
61 | | -Requirements files |
62 | | ------------------- |
63 | | - |
64 | | -:ref:`Requirements Files <pip:Requirements Files>` described most simply, are |
65 | | -just a list of :ref:`pip:pip install` arguments placed into a file. |
66 | | - |
67 | | -Whereas ``install_requires`` defines the dependencies for a single project, |
68 | | -:ref:`Requirements Files <pip:Requirements Files>` are often used to define |
69 | | -the requirements for a complete Python environment. |
70 | | - |
71 | | -Whereas ``install_requires`` requirements are minimal, requirements files |
72 | | -often contain an exhaustive listing of pinned versions for the purpose of |
73 | | -achieving :ref:`repeatable installations <pip:Repeatability>` of a complete |
74 | | -environment. |
75 | | - |
76 | | -Whereas ``install_requires`` requirements are "Abstract", i.e. not associated |
77 | | -with any particular index, requirements files often contain pip |
78 | | -options like ``--index-url`` or ``--find-links`` to make requirements |
79 | | -"Concrete", i.e. associated with a particular index or directory of |
80 | | -packages. [1]_ |
81 | | - |
82 | | -Whereas ``install_requires`` metadata is automatically analyzed by pip during an |
83 | | -install, requirements files are not, and only are used when a user specifically |
84 | | -installs them using ``python -m pip install -r``. |
| 11 | +* ``install_requires``: `Declaring required dependency`_ in the setuptools documentation. |
| 12 | +* :file:`requirements.txt`: `Requirements File Format`_ in the pip documentation. |
85 | 13 |
|
86 | | ----- |
| 14 | +This page previously explained abstract versus concrete requirements. For an |
| 15 | +explanation of that distinction, see `setup.py vs requirements.txt`_ by Donald |
| 16 | +Stufft. |
87 | 17 |
|
88 | | -.. [1] For more on "Abstract" vs "Concrete" requirements, see |
89 | | - https://caremad.io/posts/2013/07/setup-vs-requirement/. |
| 18 | +.. _Declaring required dependency: https://setuptools.pypa.io/en/latest/userguide/dependency_management.html#declaring-required-dependency |
| 19 | +.. _Requirements File Format: https://pip.pypa.io/en/stable/reference/requirements-file-format/ |
| 20 | +.. _setup.py vs requirements.txt: https://caremad.io/posts/2013/07/setup-vs-requirement/ |
0 commit comments