Skip to content

Commit 87551b9

Browse files
trallarduranusjr
authored andcommitted
Documentation: how to use pip specifiers with Pipenv
Fix #2930.
1 parent 9360058 commit 87551b9

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

docs/basics.rst

+28-3
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,38 @@ in your ``Pipfile.lock`` for now, run ``pipenv lock --keep-outdated``. Make sur
182182
☤ Specifying Versions of a Package
183183
----------------------------------
184184

185-
To tell pipenv to install a specific version of a library, the usage is simple::
185+
You can specify versions of a package using the `Semantic Versioning scheme <https://semver.org/>`_
186+
(i.e. ``major.minor.micro``).
186187

187-
$ pipenv install requests==2.13.0
188+
For example, to install requests you can use: ::
189+
190+
$ pipenv install requests~=1.2 # equivalent to requests~=1.2.0
191+
192+
Pipenv will install version ``1.2`` and any minor update, but not ``2.0``.
188193

189194
This will update your ``Pipfile`` to reflect this requirement, automatically.
190195

191-
For other version specifiers, see `the relevant section of PEP-440`_.
196+
In general, Pipenv uses the same specifier format as pip. However, note that according to `PEP 440`_ , you can't use versions containing a hyphen or a plus sign.
197+
198+
.. _`PEP 440`: <https://www.python.org/dev/peps/pep-0440/>
199+
200+
To make inclusive or exclusive version comparisons you can use: ::
201+
202+
$ pipenv install "requests>=1.4" # will install a version equal or larger than 1.4.0
203+
$ pipenv install "requests<=2.13" # will install a version equal or lower than 2.13.0
204+
$ pipenv install "requests>2.19" # will install 2.19.1 but not 2.19.0
205+
206+
.. note:: The use of ``" "`` around the package and version specification is highly recommended
207+
to avoid issues with `Input and output redirection <https://robots.thoughtbot.com/input-output-redirection-in-the-shell>`_
208+
in Unix-based operating systems.
209+
210+
The use of ``~=`` is preferred over the ``==`` identifier as the former prevents pipenv from updating the packages: ::
211+
212+
$ pipenv install "requests~=2.2" # locks the major version of the package (this is equivalent to using ==2.*)
213+
214+
To avoind installing a specific version you can use the ``!=`` identifier.
215+
216+
For an in depth explanation of the valid identifiers and more complex use cases check `the relevant section of PEP-440`_.
192217

193218
.. _`the relevant section of PEP-440`: https://www.python.org/dev/peps/pep-0440/#version-specifiers>
194219

0 commit comments

Comments
 (0)