Requirements.txt: Difference between revisions
(Created page with "=Internal= * pip {{External|https://pip.pypa.io/en/stable/cli/pip_install/}} The <code>requirements.txt</code> allows you to specify which packages...") |
No edit summary |
||
Line 1: | Line 1: | ||
=External= | |||
* https://pip.pypa.io/en/stable/cli/pip_install | |||
=Internal= | =Internal= | ||
* [[Pip#requirements.txt|pip]] | * [[Pip#requirements.txt|pip]] | ||
=Overview= | |||
The <code>requirements.txt</code> allows you to specify which packages and versions should be installed. Typically, the <code>requirements.txt</code> file is located in the root of the project. The <code>requirements.txt</code> file can be generated with <code>[[#Freeze_Dependencies|pip freeze]]</code> command. The dependencies from a <code>requirements.txt</code> file can be installed with <code>[[#dashr|pip install -r]]</code> command. | The <code>requirements.txt</code> allows you to specify which packages and versions should be installed. Typically, the <code>requirements.txt</code> file is located in the root of the project. The <code>requirements.txt</code> file can be generated with <code>[[#Freeze_Dependencies|pip freeze]]</code> command. The dependencies from a <code>requirements.txt</code> file can be installed with <code>[[#dashr|pip install -r]]</code> command. | ||
=Example= | |||
<syntaxhighlight lang='text'> | <syntaxhighlight lang='text'> | ||
pyOpenSSL==0.13.1 | pyOpenSSL==0.13.1 | ||
Line 16: | Line 15: | ||
virtualenv==16.3.0 | virtualenv==16.3.0 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=Fine Tuning Requirements= | |||
{{External|https://pip.pypa.io/en/stable/reference/requirement-specifiers/}} | {{External|https://pip.pypa.io/en/stable/reference/requirement-specifiers/}} | ||
{{External|https://peps.python.org/pep-0440/}} | {{External|https://peps.python.org/pep-0440/}} | ||
Line 30: | Line 29: | ||
The <code>~=</code> syntax means compatible release (https://peps.python.org/pep-0440/#compatible-release), matching any candidate version that is expected to be compatible with the specified version. | The <code>~=</code> syntax means compatible release (https://peps.python.org/pep-0440/#compatible-release), matching any candidate version that is expected to be compatible with the specified version. | ||
=Chaining Requirement Files= | |||
A requirements file can be "imported" in another requirements file: | A requirements file can be "imported" in another requirements file: | ||
Line 46: | Line 45: | ||
</font> | </font> | ||
=How to Lock Down Direct and Transitive Dependencies= | |||
<font color=darkkhaki> | <font color=darkkhaki> | ||
This can be done using <code>pip-compile</code>. When this is needed, process: {{Internal|pip-compile#Overview|pip-compile}} | This can be done using <code>pip-compile</code>. When this is needed, process: {{Internal|pip-compile#Overview|pip-compile}} | ||
</font> | </font> | ||
=Generate <tt>requirements.txt</tt> with Poetry= | |||
{{Internal|Poetry_Operations#export|<tt>poetry export</tt>}} |
Latest revision as of 22:06, 9 November 2023
External
Internal
Overview
The requirements.txt
allows you to specify which packages and versions should be installed. Typically, the requirements.txt
file is located in the root of the project. The requirements.txt
file can be generated with pip freeze
command. The dependencies from a requirements.txt
file can be installed with pip install -r
command.
Example
pyOpenSSL==0.13.1
pyparsing==2.0.1
python-dateutil==1.5
pytz==2013.7
scipy==0.13.0b1
six==1.4.1
virtualenv==16.3.0
Fine Tuning Requirements
The versions can be specified with a >=
operator, which say to install any version equal or newer than the specified version.
An upper bound can be specified with the <
operator:
requests>=2.21.0, <3.0
The ~=
syntax means compatible release (https://peps.python.org/pep-0440/#compatible-release), matching any candidate version that is expected to be compatible with the specified version.
Chaining Requirement Files
A requirements file can be "imported" in another requirements file:
requirements.txt
:
# this is production somepackage==1.0.0
requirements-dev.txt
:
# this is development -r requirements.txt pytest>=4.2.0
How to Lock Down Direct and Transitive Dependencies
This can be done using pip-compile
. When this is needed, process: