user_guide.rst 67.3 KB
Newer Older
M
Marcus Smith 已提交
1 2 3 4
==========
User Guide
==========

P
Pradyun Gedam 已提交
5

6
Running pip
P
Pradyun Gedam 已提交
7
===========
8 9

pip is a command line program. When you install pip, a ``pip`` command is added
10
to your system, which can be run from the command prompt as follows:
11

12
.. tab:: Unix/macOS
13

14
   .. code-block:: shell
15

16
      python -m pip <pip arguments>
17

18 19 20
   ``python -m pip`` executes pip using the Python interpreter you
   specified as python. So ``/usr/bin/python3.7 -m pip`` means
   you are executing pip for your interpreter located at /usr/bin/python3.7.
21

22
.. tab:: Windows
23

24
   .. code-block:: shell
25

26
      py -m pip <pip arguments>
27

28 29
   ``py -m pip`` executes pip using the latest Python interpreter you
   have installed. For more details, read the `Python Windows launcher`_ docs.
30 31


M
Marcus Smith 已提交
32
Installing Packages
P
Pradyun Gedam 已提交
33
===================
M
Marcus Smith 已提交
34 35 36 37 38 39

pip supports installing from `PyPI`_, version control, local projects, and
directly from distribution files.


The most common scenario is to install from `PyPI`_ using :ref:`Requirement
40 41
Specifiers`

42
.. tab:: Unix/macOS
43

44
   .. code-block:: shell
M
Marcus Smith 已提交
45

46 47 48
      python -m pip install SomePackage            # latest version
      python -m pip install SomePackage==1.0.4     # specific version
      python -m pip install 'SomePackage>=1.0.4'     # minimum version
M
Marcus Smith 已提交
49

50
.. tab:: Windows
M
Marcus Smith 已提交
51

52
   .. code-block:: shell
M
Marcus Smith 已提交
53

54 55 56
      py -m pip install SomePackage            # latest version
      py -m pip install SomePackage==1.0.4     # specific version
      py -m pip install 'SomePackage>=1.0.4'     # minimum version
M
Marcus Smith 已提交
57 58 59

For more information and examples, see the :ref:`pip install` reference.

60
.. _PyPI: https://pypi.org/
E
Erik Rose 已提交
61

M
Marcus Smith 已提交
62

63
Basic Authentication Credentials
P
Pradyun Gedam 已提交
64
================================
65

A
Andre Aguiar 已提交
66
pip supports basic authentication credentials. Basically, in the URL there is
67 68
a username and password separated by ``:``.

69
``https://[username[:password]@]pypi.company.com/simple``
70 71

Certain special characters are not valid in the authentication part of URLs.
C
Chris Hunt 已提交
72 73 74 75
If the user or password part of your login credentials contain any of the
special characters
`here <https://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding_reserved_characters>`_
then they must be percent-encoded. For example, for a
76 77 78 79 80
user with username "user" and password "he//o" accessing a repository at
pypi.company.com, the index URL with credentials would look like:

``https://user:he%2F%2Fo@pypi.company.com``

81
Support for percent-encoded authentication in index URLs was added in pip 10.0.0
82
(in `#3236 <https://github.com/pypa/pip/issues/3236>`_). Users that must use authentication
83 84 85
for their Python repository on systems with older pip versions should make the latest
get-pip.py available in their environment to bootstrap pip to a recent-enough version.

86 87
For indexes that only require single-part authentication tokens, provide the token
as the "username" and do not provide a password, for example -
88

89
``https://0123456789abcdef@pypi.company.com``
90

91

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
netrc Support
-------------

If no credentials are part of the URL, pip will attempt to get authentication credentials
for the URLs hostname from the users .netrc file. This behaviour comes from the underlying
use of `requests`_ which in turn delegates it to the `Python standard library`_.

The .netrc file contains login and initialization information used by the auto-login process.
It resides in the user's home directory. The .netrc file format is simple. You specify lines
with a machine name and follow that with lines for the login and password that are
associated with that machine. Machine name is the hostname in your URL.

An example .netrc for the host example.com with a user named 'daniel', using the password
'qwerty' would look like:

.. code-block:: shell

   machine example.com
   login daniel
   password qwerty

As mentioned in the `standard library docs <https://docs.python.org/3/library/netrc.html>`_,
114
only ASCII characters are allowed. Whitespace and non-printable characters are not allowed in passwords.
115 116


117 118 119 120
Keyring Support
---------------

pip also supports credentials stored in your keyring using the `keyring`_
121 122
library. Note that ``keyring`` will need to be installed separately, as pip
does not come with it included.
123 124 125 126 127

.. code-block:: shell

   pip install keyring
   echo your-password | keyring set pypi.company.com your-username
128
   pip install your-package --index-url https://pypi.company.com/
129 130 131 132

.. _keyring: https://pypi.org/project/keyring/


133
Using a Proxy Server
P
Pradyun Gedam 已提交
134
====================
135 136 137 138 139 140 141 142 143 144 145

When installing packages from `PyPI`_, pip requires internet access, which
in many corporate environments requires an outbound HTTP proxy server.

pip can be configured to connect through a proxy server in various ways:

* using the ``--proxy`` command-line option to specify a proxy in the form
  ``[user:passwd@]proxy.server:port``
* using ``proxy`` in a :ref:`config-file`
* by setting the standard environment-variables ``http_proxy``, ``https_proxy``
  and ``no_proxy``.
146 147
* using the environment variable ``PIP_USER_AGENT_USER_DATA`` to include
  a JSON-encoded string in the user-agent variable used in pip's requests.
148

149 150 151

.. _`Requirements Files`:

P
Pradyun Gedam 已提交
152

M
Marcus Smith 已提交
153
Requirements Files
P
Pradyun Gedam 已提交
154
==================
M
Marcus Smith 已提交
155 156

"Requirements files" are files containing a list of items to be
157 158
installed using :ref:`pip install` like so:

159
.. tab:: Unix/macOS
160

161
   .. code-block:: shell
162

163
      python -m pip install -r requirements.txt
M
Marcus Smith 已提交
164

165
.. tab:: Windows
M
Marcus Smith 已提交
166

167
   .. code-block:: shell
168

169
      py -m pip install -r requirements.txt
M
Marcus Smith 已提交
170 171 172 173

Details on the format of the files are here: :ref:`Requirements File Format`.

Logically, a Requirements file is just a list of :ref:`pip install` arguments
174 175
placed in a file. Note that you should not rely on the items in the file being
installed by pip in any particular order.
M
Marcus Smith 已提交
176 177 178 179 180 181

In practice, there are 4 common uses of Requirements files:

1. Requirements files are used to hold the result from :ref:`pip freeze` for the
   purpose of achieving :ref:`repeatable installations <Repeatability>`.  In
   this case, your requirement file contains a pinned version of everything that
182
   was installed when ``pip freeze`` was run.
M
Marcus Smith 已提交
183

184
   .. tab:: Unix/macOS
185 186 187

      .. code-block:: shell

188 189
         python -m pip freeze > requirements.txt
         python -m pip install -r requirements.txt
M
Marcus Smith 已提交
190

191
   .. tab:: Windows
192

193
      .. code-block:: shell
194

195 196
         py -m pip freeze > requirements.txt
         py -m pip install -r requirements.txt
M
Marcus Smith 已提交
197

198 199 200 201 202 203 204 205 206 207
2. Requirements files are used to force pip to properly resolve dependencies.
   pip 20.2 and earlier `doesn't have true dependency resolution
   <https://github.com/pypa/pip/issues/988>`_, but instead simply uses the first
   specification it finds for a project. E.g. if ``pkg1`` requires
   ``pkg3>=1.0`` and ``pkg2`` requires ``pkg3>=1.0,<=2.0``, and if ``pkg1`` is
   resolved first, pip will only use ``pkg3>=1.0``, and could easily end up
   installing a version of ``pkg3`` that conflicts with the needs of ``pkg2``.
   To solve this problem, you can place ``pkg3>=1.0,<=2.0`` (i.e. the correct
   specification) into your requirements file directly along with the other top
   level requirements. Like so::
M
Marcus Smith 已提交
208 209 210 211 212 213

     pkg1
     pkg2
     pkg3>=1.0,<=2.0

3. Requirements files are used to force pip to install an alternate version of a
214 215
   sub-dependency.  For example, suppose ``ProjectA`` in your requirements file
   requires ``ProjectB``, but the latest version (v1.3) has a bug, you can force
216
   pip to accept earlier versions like so::
M
Marcus Smith 已提交
217 218 219 220 221

     ProjectA
     ProjectB<1.3

4. Requirements files are used to override a dependency with a local patch that
222 223 224
   lives in version control.  For example, suppose a dependency
   ``SomeDependency`` from PyPI has a bug, and you can't wait for an upstream
   fix.
X
Xavier Fernandez 已提交
225
   You could clone/copy the src, make the fix, and place it in VCS with the tag
226 227
   ``sometag``.  You'd reference it in your requirements file with a line like
   so::
M
Marcus Smith 已提交
228 229 230

     git+https://myvcs.com/some_dependency@sometag#egg=SomeDependency

231
   If ``SomeDependency`` was previously a top-level requirement in your
M
Marcus Smith 已提交
232
   requirements file, then **replace** that line with the new line. If
233
   ``SomeDependency`` is a sub-dependency, then **add** the new line.
M
Marcus Smith 已提交
234 235 236 237


It's important to be clear that pip determines package dependencies using
`install_requires metadata
238
<https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-dependencies>`_,
239
not by discovering ``requirements.txt`` files embedded in projects.
M
Marcus Smith 已提交
240 241 242 243 244 245

See also:

* :ref:`Requirements File Format`
* :ref:`pip freeze`
* `"setup.py vs requirements.txt" (an article by Donald Stufft)
246
  <https://caremad.io/2013/07/setup-vs-requirement/>`_
M
Marcus Smith 已提交
247 248


R
Robert Collins 已提交
249 250
.. _`Constraints Files`:

P
Pradyun Gedam 已提交
251

R
Robert Collins 已提交
252
Constraints Files
P
Pradyun Gedam 已提交
253
=================
R
Robert Collins 已提交
254 255 256 257 258 259 260

Constraints files are requirements files that only control which version of a
requirement is installed, not whether it is installed or not. Their syntax and
contents is nearly identical to :ref:`Requirements Files`. There is one key
difference: Including a package in a constraints file does not trigger
installation of the package.

261 262
Use a constraints file like so:

263
.. tab:: Unix/macOS
264

265
   .. code-block:: shell
266

267
      python -m pip install -c constraints.txt
R
Robert Collins 已提交
268

269
.. tab:: Windows
R
Robert Collins 已提交
270

271
   .. code-block:: shell
272

273
      py -m pip install -c constraints.txt
R
Robert Collins 已提交
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289

Constraints files are used for exactly the same reason as requirements files
when you don't know exactly what things you want to install. For instance, say
that the "helloworld" package doesn't work in your environment, so you have a
local patched version. Some things you install depend on "helloworld", and some
don't.

One way to ensure that the patched version is used consistently is to
manually audit the dependencies of everything you install, and if "helloworld"
is present, write a requirements file to use when installing that thing.

Constraints files offer a better way: write a single constraints file for your
organisation and use that everywhere. If the thing being installed requires
"helloworld" to be installed, your fixed version specified in your constraints
file will be used.

290
Constraints file support was added in pip 7.1. In :ref:`Resolver
291 292 293 294
changes 2020` we did a fairly comprehensive overhaul, removing several
undocumented and unsupported quirks from the previous implementation,
and stripped constraints files down to being purely a way to specify
global (version) limits for packages.
M
Marcus Smith 已提交
295 296 297

.. _`Installing from Wheels`:

P
Pradyun Gedam 已提交
298

M
Marcus Smith 已提交
299
Installing from Wheels
P
Pradyun Gedam 已提交
300
======================
M
Marcus Smith 已提交
301 302 303

"Wheel" is a built, archive format that can greatly speed installation compared
to building and installing from source archives. For more information, see the
304
`Wheel docs <https://wheel.readthedocs.io>`_ , :pep:`427`, and :pep:`425`.
M
Marcus Smith 已提交
305

P
Pradyun Gedam 已提交
306
pip prefers Wheels where they are available. To disable this, use the
307
:ref:`--no-binary <install_--no-binary>` flag for :ref:`pip install`.
M
Marcus Smith 已提交
308

309 310
If no satisfactory wheels are found, pip will default to finding source
archives.
M
Marcus Smith 已提交
311 312 313 314


To install directly from a wheel archive:

315
.. tab:: Unix/macOS
316

317
   .. code-block:: shell
318

319
      python -m pip install SomePackage-1.0-py2.py3-none-any.whl
320

321
.. tab:: Windows
322

323
   .. code-block:: shell
M
Marcus Smith 已提交
324

325
      py -m pip install SomePackage-1.0-py2.py3-none-any.whl
M
Marcus Smith 已提交
326 327 328 329 330 331


For the cases where wheels are not available, pip offers :ref:`pip wheel` as a
convenience, to build wheels for all your requirements and dependencies.

:ref:`pip wheel` requires the `wheel package
332
<https://pypi.org/project/wheel/>`_ to be installed, which provides the
M
Marcus Smith 已提交
333 334
"bdist_wheel" setuptools extension that it uses.

335 336
To build wheels for your requirements and all their dependencies to a local
directory:
M
Marcus Smith 已提交
337

338
.. tab:: Unix/macOS
M
Marcus Smith 已提交
339

340
   .. code-block:: shell
M
Marcus Smith 已提交
341

342 343
      python -m pip install wheel
      python -m pip wheel --wheel-dir=/local/wheels -r requirements.txt
344

345
.. tab:: Windows
346

347
   .. code-block:: shell
348

349 350
      py -m pip install wheel
      py -m pip wheel --wheel-dir=/local/wheels -r requirements.txt
M
Marcus Smith 已提交
351

352 353
And *then* to install those requirements just using your local directory of
wheels (and not from PyPI):
M
Marcus Smith 已提交
354

355
.. tab:: Unix/macOS
356

357
   .. code-block:: shell
358

359
      python -m pip install --no-index --find-links=/local/wheels -r requirements.txt
360

361
.. tab:: Windows
M
Marcus Smith 已提交
362

363
   .. code-block:: shell
M
Marcus Smith 已提交
364

365
      py -m pip install --no-index --find-links=/local/wheels -r requirements.txt
M
Marcus Smith 已提交
366 367 368


Uninstalling Packages
P
Pradyun Gedam 已提交
369
=====================
M
Marcus Smith 已提交
370 371 372

pip is able to uninstall most packages like so:

373
.. tab:: Unix/macOS
374

375
   .. code-block:: shell
376

377
      python -m pip uninstall SomePackage
378

379
.. tab:: Windows
380

381
   .. code-block:: shell
382

383
      py -m pip uninstall SomePackage
M
Marcus Smith 已提交
384 385 386 387 388 389 390 391 392


pip also performs an automatic uninstall of an old version of a package
before upgrading to a newer version.

For more information and examples, see the :ref:`pip uninstall` reference.


Listing Packages
P
Pradyun Gedam 已提交
393
================
M
Marcus Smith 已提交
394 395 396

To list installed packages:

397
.. tab:: Unix/macOS
398

399
   .. code-block:: console
400

401 402 403 404 405
      $ python -m pip list
      docutils (0.9.1)
      Jinja2 (2.6)
      Pygments (1.5)
      Sphinx (1.1.2)
406

407
.. tab:: Windows
408

409
   .. code-block:: console
410

411 412 413 414 415
      C:\> py -m pip list
      docutils (0.9.1)
      Jinja2 (2.6)
      Pygments (1.5)
      Sphinx (1.1.2)
M
Marcus Smith 已提交
416 417 418 419


To list outdated packages, and show the latest version available:

420
.. tab:: Unix/macOS
M
Marcus Smith 已提交
421

422
   .. code-block:: console
M
Marcus Smith 已提交
423

424 425 426
      $ python -m pip list --outdated
      docutils (Current: 0.9.1 Latest: 0.10)
      Sphinx (Current: 1.1.2 Latest: 1.1.3)
427

428
.. tab:: Windows
429

430
   .. code-block:: console
431

432 433 434
      C:\> py -m pip list --outdated
      docutils (Current: 0.9.1 Latest: 0.10)
      Sphinx (Current: 1.1.2 Latest: 1.1.3)
M
Marcus Smith 已提交
435 436 437

To show details about an installed package:

438
.. tab:: Unix/macOS
439

440
   .. code-block:: console
M
Marcus Smith 已提交
441

442 443 444 445 446 447
      $ python -m pip show sphinx
      ---
      Name: Sphinx
      Version: 1.1.3
      Location: /my/env/lib/pythonx.x/site-packages
      Requires: Pygments, Jinja2, docutils
448

449
.. tab:: Windows
M
Marcus Smith 已提交
450

451
   .. code-block:: console
M
Marcus Smith 已提交
452

453 454 455 456 457 458
      C:\> py -m pip show sphinx
      ---
      Name: Sphinx
      Version: 1.1.3
      Location: /my/env/lib/pythonx.x/site-packages
      Requires: Pygments, Jinja2, docutils
M
Marcus Smith 已提交
459 460 461 462 463 464

For more information and examples, see the :ref:`pip list` and :ref:`pip show`
reference pages.


Searching for Packages
P
Pradyun Gedam 已提交
465
======================
M
Marcus Smith 已提交
466 467

pip can search `PyPI`_ for packages using the ``pip search``
468 469
command:

470
.. tab:: Unix/macOS
471

472
   .. code-block:: shell
M
Marcus Smith 已提交
473

474
      python -m pip search "query"
475

476
.. tab:: Windows
477

478
   .. code-block:: shell
M
Marcus Smith 已提交
479

480
      py -m pip search "query"
M
Marcus Smith 已提交
481 482 483 484 485 486 487 488

The query will be used to search the names and summaries of all
packages.

For more information and examples, see the :ref:`pip search` reference.

.. _`Configuration`:

P
Pradyun Gedam 已提交
489

M
Marcus Smith 已提交
490
Configuration
P
Pradyun Gedam 已提交
491
=============
M
Marcus Smith 已提交
492 493 494 495

.. _config-file:

Config file
P
Pradyun Gedam 已提交
496
-----------
M
Marcus Smith 已提交
497 498 499 500 501

pip allows you to set all command line option defaults in a standard ini
style config file.

The names and locations of the configuration files vary slightly across
502
platforms. You may have per-user, per-virtualenv or global (shared amongst
503 504 505
all users) configuration:

**Per-user**:
M
Marcus Smith 已提交
506

507 508
* On Unix the default configuration file is: :file:`$HOME/.config/pip/pip.conf`
  which respects the ``XDG_CONFIG_HOME`` environment variable.
L
Lipis 已提交
509
* On macOS the configuration file is
510 511 512
  :file:`$HOME/Library/Application Support/pip/pip.conf`
  if directory ``$HOME/Library/Application Support/pip`` exists
  else :file:`$HOME/.config/pip/pip.conf`.
513 514
* On Windows the configuration file is :file:`%APPDATA%\\pip\\pip.ini`.

515 516
There is also a legacy per-user configuration file which is also respected.
To find its location:
517

L
Lipis 已提交
518
* On Unix and macOS the configuration file is: :file:`$HOME/.pip/pip.conf`
519 520 521 522 523 524 525
* On Windows the configuration file is: :file:`%HOME%\\pip\\pip.ini`

You can set a custom path location for this config file using the environment
variable ``PIP_CONFIG_FILE``.

**Inside a virtualenv**:

L
Lipis 已提交
526
* On Unix and macOS the file is :file:`$VIRTUAL_ENV/pip.conf`
527 528
* On Windows the file is: :file:`%VIRTUAL_ENV%\\pip.ini`

529
**Global**:
530

R
Razzi Abuissa 已提交
531
* On Unix the file may be located in :file:`/etc/pip.conf`. Alternatively
532 533 534
  it may be in a "pip" subdirectory of any of the paths set in the
  environment variable ``XDG_CONFIG_DIRS`` (if it exists), for example
  :file:`/etc/xdg/pip/pip.conf`.
L
Lipis 已提交
535
* On macOS the file is: :file:`/Library/Application Support/pip/pip.conf`
536
* On Windows XP the file is:
K
Kyle Persohn 已提交
537
  :file:`C:\\Documents and Settings\\All Users\\Application Data\\pip\\pip.ini`
538
* On Windows 7 and later the file is hidden, but writeable at
K
Kyle Persohn 已提交
539
  :file:`C:\\ProgramData\\pip\\pip.ini`
540 541
* Global configuration is not supported on Windows Vista.

E
Emmanuel Arias 已提交
542
The global configuration file is shared by all Python installations.
543 544 545 546

If multiple configuration files are found by pip then they are combined in
the following order:

547
1. The global file is read
548 549
2. The per-user file is read
3. The virtualenv-specific file is read
M
Marcus Smith 已提交
550

551
Each file read overrides any values read from previous files, so if the
552
global timeout is specified in both the global file and the per-user file
553
then the latter value will be used.
M
Marcus Smith 已提交
554 555 556 557 558 559 560 561 562 563

The names of the settings are derived from the long command line option, e.g.
if you want to use a different package index (``--index-url``) and set the
HTTP timeout (``--default-timeout``) to 60 seconds your config file would
look like this:

.. code-block:: ini

    [global]
    timeout = 60
564
    index-url = https://download.zope.org/ppix
M
Marcus Smith 已提交
565 566 567

Each subcommand can be configured optionally in its own section so that every
global setting with the same name will be overridden; e.g. decreasing the
568
``timeout`` to ``10`` seconds when running the ``freeze``
R
Remi Rampin 已提交
569
(:ref:`pip freeze`) command and using
M
Marcus Smith 已提交
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
``60`` seconds for all other commands is possible with:

.. code-block:: ini

    [global]
    timeout = 60

    [freeze]
    timeout = 10


Boolean options like ``--ignore-installed`` or ``--no-dependencies`` can be
set like this:

.. code-block:: ini

    [install]
    ignore-installed = true
    no-dependencies = yes

590 591
To enable the boolean options ``--no-compile``, ``--no-warn-script-location``
and ``--no-cache-dir``, falsy values have to be used:
592 593 594 595 596 597 598 599

.. code-block:: ini

    [global]
    no-cache-dir = false

    [install]
    no-compile = no
600
    no-warn-script-location = false
601

602 603 604 605 606 607 608 609 610
For options which can be repeated like ``--verbose`` and ``--quiet``,
a non-negative integer can be used to represent the level to be specified:

.. code-block:: ini

    [global]
    quiet = 0
    verbose = 2

611 612 613
It is possible to append values to a section within a configuration file such as the pip.ini file.
This is applicable to appending options like ``--find-links`` or ``--trusted-host``,
which can be written on multiple lines:
M
Marcus Smith 已提交
614 615 616 617 618 619 620 621 622 623 624 625

.. code-block:: ini

    [global]
    find-links =
        http://download.example.com

    [install]
    find-links =
        http://mirror1.example.com
        http://mirror2.example.com

626
    trusted-host =
627 628
        mirror1.example.com
        mirror2.example.com
629 630 631

This enables users to add additional values in the order of entry for such command line arguments.

M
Marcus Smith 已提交
632 633 634 635 636 637 638 639

Environment Variables
---------------------

pip's command line options can be set with environment variables using the
format ``PIP_<UPPER_LONG_NAME>`` . Dashes (``-``) have to be replaced with
underscores (``_``).

640 641
For example, to set the default timeout:

642
.. tab:: Unix/macOS
643

644
   .. code-block:: shell
645

646
      export PIP_DEFAULT_TIMEOUT=60
647

648
.. tab:: Windows
649

650
   .. code-block:: shell
651

652
      set PIP_DEFAULT_TIMEOUT=60
653 654 655

This is the same as passing the option to pip directly:

656
.. tab:: Unix/macOS
M
Marcus Smith 已提交
657

658
   .. code-block:: shell
M
Marcus Smith 已提交
659

660
      python -m pip --default-timeout=60 [...]
M
Marcus Smith 已提交
661

662
.. tab:: Windows
663

664
   .. code-block:: shell
665

666
      py -m pip --default-timeout=60 [...]
M
Marcus Smith 已提交
667

668
For command line options which can be repeated, use a space to separate
669
multiple values. For example:
M
Marcus Smith 已提交
670

671
.. tab:: Unix/macOS
672

673
   .. code-block:: shell
674

675
      export PIP_FIND_LINKS="http://mirror1.example.com http://mirror2.example.com"
676

677
.. tab:: Windows
678

679
   .. code-block:: shell
680

681
      set PIP_FIND_LINKS="http://mirror1.example.com http://mirror2.example.com"
682 683 684

is the same as calling:

685
.. tab:: Unix/macOS
686

687
   .. code-block:: shell
688

689
      python -m pip install --find-links=http://mirror1.example.com --find-links=http://mirror2.example.com
690

691
.. tab:: Windows
692

693
   .. code-block:: shell
M
Marcus Smith 已提交
694

695
      py -m pip install --find-links=http://mirror1.example.com --find-links=http://mirror2.example.com
M
Marcus Smith 已提交
696

697 698 699 700 701 702 703 704 705
Options that do not take a value, but can be repeated (such as ``--verbose``)
can be specified using the number of repetitions, so::

    export PIP_VERBOSE=3

is the same as calling::

    pip install -vvv

706 707
.. note::

708 709
   Environment variables set to be empty string will not be treated as false.
   Please use ``no``, ``false`` or ``0`` instead.
710

M
Marcus Smith 已提交
711

712 713
.. _config-precedence:

M
Marcus Smith 已提交
714 715 716
Config Precedence
-----------------

717 718
Command line options have precedence over environment variables, which have
precedence over the config file.
M
Marcus Smith 已提交
719

720 721
Within the config file, command specific sections have precedence over the
global section.
M
Marcus Smith 已提交
722 723 724 725 726 727 728 729 730 731

Examples:

- ``--host=foo`` overrides ``PIP_HOST=foo``
- ``PIP_HOST=foo`` overrides a config file with ``[global] host = foo``
- A command specific section in the config file ``[<command>] host = bar``
  overrides the option with same name in the ``[global]`` config file section


Command Completion
P
Pradyun Gedam 已提交
732
==================
M
Marcus Smith 已提交
733

734
pip comes with support for command line completion in bash, zsh and fish.
M
Marcus Smith 已提交
735 736 737

To setup for bash::

738
    python -m pip completion --bash >> ~/.profile
M
Marcus Smith 已提交
739 740 741

To setup for zsh::

742
    python -m pip completion --zsh >> ~/.zprofile
M
Marcus Smith 已提交
743

744 745
To setup for fish::

746
    python -m pip completion --fish > ~/.config/fish/completions/pip.fish
747

748 749 750
Alternatively, you can use the result of the ``completion`` command directly
with the eval function of your shell, e.g. by adding the following to your
startup file::
M
Marcus Smith 已提交
751 752 753 754 755

    eval "`pip completion --bash`"



756
.. _`Installing from local packages`:
M
Marcus Smith 已提交
757

P
Pradyun Gedam 已提交
758

759
Installing from local packages
P
Pradyun Gedam 已提交
760
==============================
M
Marcus Smith 已提交
761

762 763
In some cases, you may want to install from local packages only, with no traffic
to PyPI.
M
Marcus Smith 已提交
764

765 766
First, download the archives that fulfill your requirements:

767
.. tab:: Unix/macOS
768

769
   .. code-block:: shell
770

771
      python -m pip download --destination-directory DIR -r requirements.txt
M
Marcus Smith 已提交
772

773
.. tab:: Windows
774

775
   .. code-block:: shell
776

777
      py -m pip download --destination-directory DIR -r requirements.txt
778

X
xtreak 已提交
779
Note that ``pip download`` will look in your wheel cache first, before
780 781 782
trying to download from PyPI.  If you've never installed your requirements
before, you won't have a wheel cache for those items.  In that case, if some of
your requirements don't come as wheels from PyPI, and you want wheels, then run
783 784
this instead:

785
.. tab:: Unix/macOS
786

787
   .. code-block:: shell
788

789
      python -m pip wheel --wheel-dir DIR -r requirements.txt
790

791
.. tab:: Windows
792

793
   .. code-block:: shell
794

795
      py -m pip wheel --wheel-dir DIR -r requirements.txt
M
Marcus Smith 已提交
796

797
Then, to install from local only, you'll be using :ref:`--find-links
798 799
<install_--find-links>` and :ref:`--no-index <install_--no-index>` like so:

800
.. tab:: Unix/macOS
801

802
   .. code-block:: shell
M
Marcus Smith 已提交
803

804
      python -m pip install --no-index --find-links=DIR -r requirements.txt
M
Marcus Smith 已提交
805

806
.. tab:: Windows
807

808
   .. code-block:: shell
809

810
      py -m pip install --no-index --find-links=DIR -r requirements.txt
M
Marcus Smith 已提交
811 812


813
"Only if needed" Recursive Upgrade
P
Pradyun Gedam 已提交
814
==================================
M
Marcus Smith 已提交
815

816 817 818
``pip install --upgrade`` now has a ``--upgrade-strategy`` option which
controls how pip handles upgrading of dependencies. There are 2 upgrade
strategies supported:
M
Marcus Smith 已提交
819

820 821 822 823
- ``eager``: upgrades all dependencies regardless of whether they still satisfy
  the new parent requirements
- ``only-if-needed``: upgrades a dependency only if it does not satisfy the new
  parent requirements
824 825 826

The default strategy is ``only-if-needed``. This was changed in pip 10.0 due to
the breaking nature of ``eager`` when upgrading conflicting dependencies.
M
Marcus Smith 已提交
827

828 829 830 831 832 833 834 835 836 837 838 839 840 841 842
It is important to note that ``--upgrade`` affects *direct requirements* (e.g.
those specified on the command-line or via a requirements file) while
``--upgrade-strategy`` affects *indirect requirements* (dependencies of direct
requirements).

As an example, say ``SomePackage`` has a dependency, ``SomeDependency``, and
both of them are already installed but are not the latest avaialable versions:

- ``pip install SomePackage``: will not upgrade the existing ``SomePackage`` or
  ``SomeDependency``.
- ``pip install --upgrade SomePackage``: will upgrade ``SomePackage``, but not
  ``SomeDependency`` (unless a minimum requirement is not met).
- ``pip install --upgrade SomePackage --upgrade-strategy=eager``: upgrades both
  ``SomePackage`` and ``SomeDependency``.

843
As an historic note, an earlier "fix" for getting the ``only-if-needed``
844 845
behaviour was:

846
.. tab:: Unix/macOS
847

848
   .. code-block:: shell
849

850 851
      python -m pip install --upgrade --no-deps SomePackage
      python -m pip install SomePackage
852

853
.. tab:: Windows
854

855
   .. code-block:: shell
856

857 858
      py -m pip install --upgrade --no-deps SomePackage
      py -m pip install SomePackage
M
Marcus Smith 已提交
859 860


861 862
A proposal for an ``upgrade-all`` command is being considered as a safer
alternative to the behaviour of eager upgrading.
M
Marcus Smith 已提交
863 864 865


User Installs
P
Pradyun Gedam 已提交
866
=============
M
Marcus Smith 已提交
867 868

With Python 2.6 came the `"user scheme" for installation
869
<https://docs.python.org/3/install/index.html#alternate-installation-the-user-scheme>`_,
M
Marcus Smith 已提交
870 871 872
which means that all Python distributions support an alternative install
location that is specific to a user.  The default location for each OS is
explained in the python documentation for the `site.USER_BASE
873 874
<https://docs.python.org/3/library/site.html#site.USER_BASE>`_ variable.
This mode of installation can be turned on by specifying the :ref:`--user
M
Marcus Smith 已提交
875 876 877
<install_--user>` option to ``pip install``.

Moreover, the "user scheme" can be customized by setting the
878 879
``PYTHONUSERBASE`` environment variable, which updates the value of
``site.USER_BASE``.
M
Marcus Smith 已提交
880

881
To install "SomePackage" into an environment with site.USER_BASE customized to
882 883
'/myappenv', do the following:

884
.. tab:: Unix/macOS
M
Marcus Smith 已提交
885

886
   .. code-block:: shell
887

888 889
      export PYTHONUSERBASE=/myappenv
      python -m pip install --user SomePackage
M
Marcus Smith 已提交
890

891
.. tab:: Windows
M
Marcus Smith 已提交
892

893
   .. code-block:: shell
894

895 896
      set PYTHONUSERBASE=c:/myappenv
      py -m pip install --user SomePackage
M
Marcus Smith 已提交
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917

``pip install --user`` follows four rules:

#. When globally installed packages are on the python path, and they *conflict*
   with the installation requirements, they are ignored, and *not*
   uninstalled.
#. When globally installed packages are on the python path, and they *satisfy*
   the installation requirements, pip does nothing, and reports that
   requirement is satisfied (similar to how global packages can satisfy
   requirements when installing packages in a ``--system-site-packages``
   virtualenv).
#. pip will not perform a ``--user`` install in a ``--no-site-packages``
   virtualenv (i.e. the default kind of virtualenv), due to the user site not
   being on the python path.  The installation would be pointless.
#. In a ``--system-site-packages`` virtualenv, pip will not install a package
   that conflicts with a package in the virtualenv site-packages.  The --user
   installation would lack sys.path precedence and be pointless.


To make the rules clearer, here are some examples:

918 919
From within a ``--no-site-packages`` virtualenv (i.e. the default kind):

920
.. tab:: Unix/macOS
921

922
   .. code-block:: console
M
Marcus Smith 已提交
923

924 925
      $ python -m pip install --user SomePackage
      Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
926

927
.. tab:: Windows
928

929
   .. code-block:: console
M
Marcus Smith 已提交
930

931 932
      C:\> py -m pip install --user SomePackage
      Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
M
Marcus Smith 已提交
933 934


935
From within a ``--system-site-packages`` virtualenv where ``SomePackage==0.3``
936
is already installed in the virtualenv:
M
Marcus Smith 已提交
937

938
.. tab:: Unix/macOS
M
Marcus Smith 已提交
939

940
   .. code-block:: console
M
Marcus Smith 已提交
941

942 943
      $ python -m pip install --user SomePackage==0.4
      Will not install to the user site because it will lack sys.path precedence
M
Marcus Smith 已提交
944

945
.. tab:: Windows
M
Marcus Smith 已提交
946

947
   .. code-block:: console
948

949 950
      C:\> py -m pip install --user SomePackage==0.4
      Will not install to the user site because it will lack sys.path precedence
M
Marcus Smith 已提交
951

952
From within a real python, where ``SomePackage`` is *not* installed globally:
M
Marcus Smith 已提交
953

954
.. tab:: Unix/macOS
M
Marcus Smith 已提交
955

956
   .. code-block:: console
957

958 959 960
      $ python -m pip install --user SomePackage
      [...]
      Successfully installed SomePackage
961

962
.. tab:: Windows
M
Marcus Smith 已提交
963

964
   .. code-block:: console
M
Marcus Smith 已提交
965

966 967 968
      C:\> py -m pip install --user SomePackage
      [...]
      Successfully installed SomePackage
M
Marcus Smith 已提交
969

970
From within a real python, where ``SomePackage`` *is* installed globally, but
971
is *not* the latest version:
M
Marcus Smith 已提交
972

973
.. tab:: Unix/macOS
M
Marcus Smith 已提交
974

975
   .. code-block:: console
M
Marcus Smith 已提交
976

977 978 979 980 981 982
      $ python -m pip install --user SomePackage
      [...]
      Requirement already satisfied (use --upgrade to upgrade)
      $ python -m pip install --user --upgrade SomePackage
      [...]
      Successfully installed SomePackage
983

984
.. tab:: Windows
985

986
   .. code-block:: console
987

988 989 990 991 992 993
      C:\> py -m pip install --user SomePackage
      [...]
      Requirement already satisfied (use --upgrade to upgrade)
      C:\> py -m pip install --user --upgrade SomePackage
      [...]
      Successfully installed SomePackage
M
Marcus Smith 已提交
994

995
From within a real python, where ``SomePackage`` *is* installed globally, and
996 997
is the latest version:

998
.. tab:: Unix/macOS
M
Marcus Smith 已提交
999

1000
   .. code-block:: console
M
Marcus Smith 已提交
1001

1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
      $ python -m pip install --user SomePackage
      [...]
      Requirement already satisfied (use --upgrade to upgrade)
      $ python -m pip install --user --upgrade SomePackage
      [...]
      Requirement already up-to-date: SomePackage
      # force the install
      $ python -m pip install --user --ignore-installed SomePackage
      [...]
      Successfully installed SomePackage
M
Marcus Smith 已提交
1012

1013
.. tab:: Windows
M
Marcus Smith 已提交
1014

1015
   .. code-block:: console
1016

1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
      C:\> py -m pip install --user SomePackage
      [...]
      Requirement already satisfied (use --upgrade to upgrade)
      C:\> py -m pip install --user --upgrade SomePackage
      [...]
      Requirement already up-to-date: SomePackage
      # force the install
      C:\> py -m pip install --user --ignore-installed SomePackage
      [...]
      Successfully installed SomePackage
M
Marcus Smith 已提交
1027 1028 1029

.. _`Repeatability`:

P
Pradyun Gedam 已提交
1030

M
Marcus Smith 已提交
1031
Ensuring Repeatability
P
Pradyun Gedam 已提交
1032
======================
M
Marcus Smith 已提交
1033

E
Erik Rose 已提交
1034 1035 1036 1037 1038 1039 1040
pip can achieve various levels of repeatability:

Pinned Version Numbers
----------------------

Pinning the versions of your dependencies in the requirements file
protects you from bugs or incompatibilities in newly released versions::
M
Marcus Smith 已提交
1041

E
Erik Rose 已提交
1042 1043
    SomePackage == 1.2.3
    DependencyOfSomePackage == 4.5.6
M
Marcus Smith 已提交
1044

E
Erik Rose 已提交
1045 1046 1047 1048 1049
Using :ref:`pip freeze` to generate the requirements file will ensure that not
only the top-level dependencies are included but their sub-dependencies as
well, and so on. Perform the installation using :ref:`--no-deps
<install_--no-deps>` for an extra dose of insurance against installing
anything not explicitly listed.
M
Marcus Smith 已提交
1050

E
Erik Rose 已提交
1051
This strategy is easy to implement and works across OSes and architectures.
1052 1053 1054 1055
However, it trusts PyPI and the certificate authority chain. It
also relies on indices and find-links locations not allowing
packages to change without a version increase. (PyPI does protect
against this.)
1056

E
Erik Rose 已提交
1057 1058 1059 1060 1061
Hash-checking Mode
------------------

Beyond pinning version numbers, you can add hashes against which to verify
downloaded packages::
M
Marcus Smith 已提交
1062

1063
    FooProject == 1.2 --hash=sha256:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
M
Marcus Smith 已提交
1064

1065 1066 1067 1068
This protects against a compromise of PyPI or the HTTPS
certificate chain. It also guards against a package changing
without its version number changing (on indexes that allow this).
This approach is a good fit for automated server deployments.
1069

E
Erik Rose 已提交
1070
Hash-checking mode is a labor-saving alternative to running a private index
E
Erik Rose 已提交
1071
server containing approved packages: it removes the need to upload packages,
E
Erik Rose 已提交
1072
maintain ACLs, and keep an audit trail (which a VCS gives you on the
E
Erik Rose 已提交
1073 1074
requirements file for free). It can also substitute for a vendor library,
providing easier upgrades and less VCS noise. It does not, of course,
E
Erik Rose 已提交
1075
provide the availability benefits of a private index or a vendor library.
E
Erik Rose 已提交
1076

1077 1078
For more, see
:ref:`pip install\'s discussion of hash-checking mode <hash-checking mode>`.
1079 1080 1081

.. _`Installation Bundle`:

E
Erik Rose 已提交
1082 1083
Installation Bundles
--------------------
1084

1085 1086 1087 1088
Using :ref:`pip wheel`, you can bundle up all of a project's dependencies, with
any compilation done, into a single archive. This allows installation when
index servers are unavailable and avoids time-consuming recompilation. Create
an archive like this::
1089 1090

    $ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
1091
    $ python -m pip wheel -r requirements.txt --wheel-dir=$tempdir
1092 1093 1094
    $ cwd=`pwd`
    $ (cd "$tempdir"; tar -cjvf "$cwd/bundled.tar.bz2" *)

1095
You can then install from the archive like this::
1096 1097 1098

    $ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
    $ (cd $tempdir; tar -xvf /path/to/bundled.tar.bz2)
1099
    $ python -m pip install --force-reinstall --ignore-installed --upgrade --no-index --no-deps $tempdir/*
E
Erik Rose 已提交
1100

1101
Note that compiled packages are typically OS- and architecture-specific, so
1102
these archives are not necessarily portable across machines.
1103 1104 1105

Hash-checking mode can be used along with this method to ensure that future
archives are built with identical packages.
E
Erik Rose 已提交
1106 1107

.. warning::
1108

E
Erik Rose 已提交
1109 1110 1111 1112 1113
    Finally, beware of the ``setup_requires`` keyword arg in :file:`setup.py`.
    The (rare) packages that use it will cause those dependencies to be
    downloaded by setuptools directly, skipping pip's protections. If you need
    to use such a package, see :ref:`Controlling
    setup_requires<controlling-setup-requires>`.
1114

1115 1116
.. _`Fixing conflicting dependencies`:

N
Nicole Harris 已提交
1117 1118 1119 1120 1121 1122 1123 1124
Fixing conflicting dependencies
===============================

The purpose of this section of documentation is to provide practical suggestions to
pip users who encounter an error where pip cannot install their
specified packages due to conflicting dependencies (a
``ResolutionImpossible`` error).

1125 1126 1127 1128
This documentation is specific to the new resolver, which is the
default behavior in pip 20.3 and later. If you are using pip 20.2, you
can invoke the new resolver by using the flag
``--use-feature=2020-resolver``.
N
Nicole Harris 已提交
1129 1130 1131 1132 1133 1134 1135

Understanding your error message
--------------------------------

When you get a ``ResolutionImpossible`` error, you might see something
like this:

1136
.. tab:: Unix/macOS
1137

1138
   .. code-block:: shell
1139

1140
      python -m pip install package_coffee==0.44.1 package_tea==4.3.0
1141

1142
.. tab:: Windows
1143

1144
   .. code-block:: shell
1145

1146
      py -m pip install package_coffee==0.44.1 package_tea==4.3.0
1147 1148

::
N
Nicole Harris 已提交
1149

1150 1151 1152 1153
   Due to conflicting dependencies pip cannot install
   package_coffee and package_tea:
   - package_coffee depends on package_water<3.0.0,>=2.4.2
   - package_tea depends on package_water==2.3.1
N
Nicole Harris 已提交
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171

In this example, pip cannot install the packages you have requested,
because they each depend on different versions of the same package
(``package_water``):

- ``package_coffee`` version ``0.44.1`` depends on a version of
  ``package_water`` that is less than ``3.0.0`` but greater than or equal to
  ``2.4.2``
- ``package_tea`` version ``4.3.0`` depends on version ``2.3.1`` of
  ``package_water``

Sometimes these messages are straightforward to read, because they use
commonly understood comparison operators to specify the required version
(e.g. ``<`` or ``>``).

However, Python packaging also supports some more complex ways for
specifying package versions (e.g. ``~=`` or ``*``):

1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
+----------+---------------------------------+--------------------------------+
| Operator | Description                     | Example                        |
+==========+=================================+================================+
|  ``>``   | Any version greater than        | ``>3.1``: any version          |
|          | the specified version.          | greater than ``3.1``.          |
+----------+---------------------------------+--------------------------------+
|  ``<``   | Any version less than           | ``<3.1``: any version          |
|          | the specified version.          | less than ``3.1``.             |
+----------+---------------------------------+--------------------------------+
|  ``<=``  | Any version less than or        | ``<=3.1``: any version         |
|          | equal to the specified version. | less than or equal to ``3.1``. |
+----------+---------------------------------+--------------------------------+
|  ``>=``  | Any version greater than or     | ``>=3.1``:                     |
|          | equal to the specified version. | version ``3.1`` and greater.   |
+----------+---------------------------------+--------------------------------+
|  ``==``  | Exactly the specified version.  | ``==3.1``: only ``3.1``.       |
+----------+---------------------------------+--------------------------------+
|  ``!=``  | Any version not equal           | ``!=3.1``: any version         |
|          | to the specified version.       | other than ``3.1``.            |
+----------+---------------------------------+--------------------------------+
|  ``~=``  | Any compatible release.         | ``~=3.1``: version ``3.1``     |
|          | Compatible releases are         | or later, but not              |
|          | releases that are within the    | version ``4.0`` or later.      |
|          | same major or minor version,    | ``~=3.1.2``: version ``3.1.2`` |
|          | assuming the package author     | or later, but not              |
|          | is using semantic versioning.   | version ``3.2.0`` or later.    |
+----------+---------------------------------+--------------------------------+
|  ``*``   | Can be used at the end of       | ``==3.1.*``: any version       |
|          | a version number to represent   | that starts with ``3.1``.      |
|          | *all*,                          | Equivalent to ``~=3.1.0``.     |
+----------+---------------------------------+--------------------------------+
N
Nicole Harris 已提交
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239

The detailed specification of supported comparison operators can be
found in :pep:`440`.

Possible solutions
------------------

The solution to your error will depend on your individual use case. Here
are some things to try:

1. Audit your top level requirements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

As a first step it is useful to audit your project and remove any
unnecessary or out of date requirements (e.g. from your ``setup.py`` or
``requirements.txt`` files). Removing these can significantly reduce the
complexity of your dependency tree, thereby reducing opportunities for
conflicts to occur.

2. Loosen your top level requirements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Sometimes the packages that you have asked pip to install are
incompatible because you have been too strict when you specified the
package version.

In our first example both ``package_coffee`` and ``package_tea`` have been
*pinned* to use specific versions
(``package_coffee==0.44.1b0 package_tea==4.3.0``).

To find a version of both ``package_coffee`` and ``package_tea`` that depend on
the same version of ``package_water``, you might consider:

-  Loosening the range of packages that you are prepared to install
   (e.g. ``pip install "package_coffee>0.44.*" "package_tea>4.0.0"``)
-  Asking pip to install *any* version of ``package_coffee`` and ``package_tea``
   by removing the version specifiers altogether (e.g.
1240
   ``python -m pip install package_coffee package_tea``)
N
Nicole Harris 已提交
1241 1242 1243 1244 1245 1246 1247 1248 1249

In the second case, pip will automatically find a version of both
``package_coffee`` and ``package_tea`` that depend on the same version of
``package_water``, installing:

-  ``package_coffee 0.46.0b0``, which depends on ``package_water 2.6.1``
-  ``package_tea 4.3.0`` which *also* depends on ``package_water 2.6.1``

If you want to prioritize one package over another, you can add version
1250 1251
specifiers to *only* the more important package:

1252
.. tab:: Unix/macOS
1253

1254
   .. code-block:: shell
1255

1256
      python -m pip install package_coffee==0.44.1b0 package_tea
1257

1258
.. tab:: Windows
1259

1260
   .. code-block:: shell
N
Nicole Harris 已提交
1261

1262
      py -m pip install package_coffee==0.44.1b0 package_tea
N
Nicole Harris 已提交
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299

This will result in:

- ``package_coffee 0.44.1b0``, which depends on ``package_water 2.6.1``
- ``package_tea 4.1.3`` which also depends on ``package_water 2.6.1``

Now that you have resolved the issue, you can repin the compatible
package versions as required.

3. Loosen the requirements of your dependencies
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Assuming that you cannot resolve the conflict by loosening the version
of the package you require (as above), you can try to fix the issue on
your *dependency* by:

-  Requesting that the package maintainers loosen *their* dependencies
-  Forking the package and loosening the dependencies yourself

.. warning::

   If you choose to fork the package yourself, you are *opting out* of
   any support provided by the package maintainers. Proceed at your own risk!

4. All requirements are loose, but a solution does not exist
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Sometimes it's simply impossible to find a combination of package
versions that do not conflict. Welcome to `dependency hell`_.

In this situation, you could consider:

-  Using an alternative package, if that is acceptable for your project.
   See `Awesome Python`_ for similar packages.
-  Refactoring your project to reduce the number of dependencies (for
   example, by breaking up a monolithic code base into smaller pieces)

B
Bernard 已提交
1300 1301
.. _`Getting help`:

N
Nicole Harris 已提交
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
Getting help
------------

If none of the suggestions above work for you, we recommend that you ask
for help on:

-  `Python user Discourse`_
-  `Python user forums`_
-  `Python developers Slack channel`_
-  `Python IRC`_
-  `Stack Overflow`_

See `"How do I ask a good question?"`_ for tips on asking for help.

Unfortunately, **the pip team cannot provide support for individual
dependency conflict errors**. Please *only* open a ticket on the `pip
issue tracker`_ if you believe that your problem has exposed a bug in pip.

1320
.. _dependency hell: https://en.wikipedia.org/wiki/Dependency_hell
N
Nicole Harris 已提交
1321 1322 1323 1324 1325 1326 1327 1328
.. _Awesome Python: https://python.libhunt.com/
.. _Python user Discourse: https://discuss.python.org/c/users/7
.. _Python user forums: https://www.python.org/community/forums/
.. _Python developers Slack channel: https://pythondev.slack.com/
.. _Python IRC: https://www.python.org/community/irc/
.. _Stack Overflow: https://stackoverflow.com/questions/tagged/python
.. _"How do I ask a good question?": https://stackoverflow.com/help/how-to-ask
.. _pip issue tracker: https://github.com/pypa/pip/issues
P
Pradyun Gedam 已提交
1329

1330
.. _`Dependency resolution backtracking`:
1331

B
WIP  
Bernard 已提交
1332 1333 1334 1335
Dependency resolution backtracking
==================================

Or more commonly known as *"Why does pip download multiple versions of
1336
the same package over and over again during an install?"*.
B
WIP  
Bernard 已提交
1337

1338 1339
The purpose of this section is to provide explanation of why
backtracking happens, and practical suggestions to pip users who
1340
encounter it during a ``pip install``.
B
WIP  
Bernard 已提交
1341 1342 1343 1344

What is backtracking?
---------------------

1345 1346 1347
Backtracking is not a bug, or an unexpected behaviour. It is part of the
way pip's dependency resolution process works.

B
WIP  
Bernard 已提交
1348
During a pip install (e.g. ``pip install tea``), pip needs to work out
1349
the package's dependencies (e.g. ``spoon``, ``hot-water``, ``cup`` etc.), the
B
Bernard Tyers 已提交
1350 1351
versions of each of these packages it needs to install. For each package
pip needs to decide which version is a good candidate to install.
B
Bernard 已提交
1352

1353 1354
A "good candidate" means a version of each package that is compatible with all
the other package versions being installed at the same time.
1355 1356 1357

In the case where a package has a lot of versions, arriving at a good
candidate can take a lot of time. (The amount of time depends on the
B
Bernard 已提交
1358
package size, the number of versions pip must try, and other concerns.)
1359 1360

How does backtracking work?
1361
^^^^^^^^^^^^^^^^^^^^^^^^^^^
1362

B
Bernard Tyers 已提交
1363
When doing a pip install, pip starts by making assumptions about the
B
Bernard 已提交
1364
packages it needs to install. During the install process it needs to check these
B
Bernard 已提交
1365
assumptions as it goes along.
B
WIP  
Bernard 已提交
1366

B
Bernard Tyers 已提交
1367
When pip finds that an assumption is incorrect, it has to try another approach
B
Bernard 已提交
1368 1369 1370
(backtrack), which means discarding some of the work that has already been done,
and going back to choose another path.

1371
For example; The user requests ``pip install tea``. ``tea`` has dependencies of
1372
``cup``, ``hot-water``, ``spoon`` amongst others.
1373

1374 1375 1376
pip starts by installing a version of ``cup``. If it finds out it isnt
compatible (with the other package versions) it needs to go back
(backtrack) and download an older version.
B
Bernard 已提交
1377 1378 1379 1380

It then tries to install that version. If it is successful, it will continue
onto the next package. If not it will continue to backtrack until it finds a
compatible version.
B
WIP  
Bernard 已提交
1381 1382

This backtrack behaviour can end in 2 ways - either 1) it will
B
Bernard 已提交
1383
successfully find a set of packages it can install (good news!), or 2) it will
B
Bernard Tyers 已提交
1384
eventually display a `resolution impossible <https://pip.pypa.io/en/latest/user_guide/#id35>`__ error
1385
message (not so good).
B
WIP  
Bernard 已提交
1386 1387 1388

If pip starts backtracking during dependency resolution, it does not
know how long it will backtrack, and how much computation would be
1389
needed. For the user this means it can take a long time to complete.
B
WIP  
Bernard 已提交
1390

1391 1392 1393
Why does backtracking occur?
----------------------------

B
Bernard 已提交
1394
With the release of the new resolver (:ref:`Resolver changes 2020`), pip is now
B
Bernard 已提交
1395
more strict in the package versions it installs when a user runs a
B
Bernard 已提交
1396 1397 1398 1399 1400 1401
``pip install`` command.

Pip needs to backtrack because initially, it doesn't have all the information it
needs to work out the correct set of packages. This is because package indexes
don't provide full package dependency information before you have downloaded
the package.
B
WIP  
Bernard 已提交
1402

1403 1404 1405
This new resolver behaviour means that pip works harder to find out which
version of a package is a good candidate to install. It reduces the risk that
installing a new package will accidentally break an existing installed package,
B
Bernard Tyers 已提交
1406 1407
and so reduces the risk that your environment gets messed up.

B
WIP  
Bernard 已提交
1408 1409 1410
What does this behaviour look like?
-----------------------------------

1411
Right now backtracking behaviour looks like this:
1412

B
WIP  
Bernard 已提交
1413 1414 1415 1416
::

   $ pip install tea==1.9.8
   Collecting tea==1.9.8
B
Bernard 已提交
1417 1418
     Downloading tea-1.9.8-py2.py3-none-any.whl (346 kB)
        |████████████████████████████████| 346 kB 10.4 MB/s
B
WIP  
Bernard 已提交
1419
   Collecting spoon==2.27.0
B
Bernard 已提交
1420 1421
     Downloading spoon-2.27.0-py2.py3-none-any.whl (312 kB)
        |████████████████████████████████| 312 kB 19.2 MB/s
B
WIP  
Bernard 已提交
1422 1423 1424
   Collecting hot-water>=0.1.9
   Downloading hot-water-0.1.13-py3-none-any.whl (9.3 kB)
   Collecting cup>=1.6.0
B
Bernard 已提交
1425 1426
     Downloading cup-3.22.0-py2.py3-none-any.whl (397 kB)
        |████████████████████████████████| 397 kB 28.2 MB/s
B
WIP  
Bernard 已提交
1427 1428 1429
   INFO: pip is looking at multiple versions of this package to determine
   which version is compatible with other requirements.
   This could take a while.
B
Bernard 已提交
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445
     Downloading cup-3.21.0-py2.py3-none-any.whl (395 kB)
        |████████████████████████████████| 395 kB 27.0 MB/s
     Downloading cup-3.20.0-py2.py3-none-any.whl (394 kB)
        |████████████████████████████████| 394 kB 24.4 MB/s
     Downloading cup-3.19.1-py2.py3-none-any.whl (394 kB)
        |████████████████████████████████| 394 kB 21.3 MB/s
     Downloading cup-3.19.0-py2.py3-none-any.whl (394 kB)
        |████████████████████████████████| 394 kB 26.2 MB/s
     Downloading cup-3.18.0-py2.py3-none-any.whl (393 kB)
        |████████████████████████████████| 393 kB 22.1 MB/s
     Downloading cup-3.17.0-py2.py3-none-any.whl (382 kB)
        |████████████████████████████████| 382 kB 23.8 MB/s
     Downloading cup-3.16.0-py2.py3-none-any.whl (376 kB)
        |████████████████████████████████| 376 kB 27.5 MB/s
     Downloading cup-3.15.1-py2.py3-none-any.whl (385 kB)
        |████████████████████████████████| 385 kB 30.4 MB/s
B
WIP  
Bernard 已提交
1446 1447 1448
   INFO: pip is looking at multiple versions of this package to determine
   which version is compatible with other requirements.
   This could take a while.
B
Bernard 已提交
1449 1450 1451 1452 1453 1454
     Downloading cup-3.15.0-py2.py3-none-any.whl (378 kB)
        |████████████████████████████████| 378 kB 21.4 MB/s
     Downloading cup-3.14.0-py2.py3-none-any.whl (372 kB)
        |████████████████████████████████| 372 kB 21.1 MB/s
     Downloading cup-3.13.1-py2.py3-none-any.whl (381 kB)
        |████████████████████████████████| 381 kB 21.8 MB/s
B
WIP  
Bernard 已提交
1455 1456 1457
   This is taking longer than usual. You might need to provide the
   dependency resolver with stricter constraints to reduce runtime.
   If you want to abort this run, you can press Ctrl + C to do so.
B
Bernard 已提交
1458
     Downloading cup-3.13.0-py2.py3-none-any.whl (374 kB)
B
WIP  
Bernard 已提交
1459

B
Bernard 已提交
1460
In the above sample output, pip had to download multiple versions of
1461 1462
package ``cup`` - cup-3.22.0 to cup-3.13.0 - to find a version that will be
compatible with the other packages - ``spoon``, ``hot-water``, etc.
B
WIP  
Bernard 已提交
1463

B
Bernard 已提交
1464
These multiple ``Downloading cup-version`` lines show pip backtracking.
B
WIP  
Bernard 已提交
1465

B
Bernard 已提交
1466
Possible ways to reduce backtracking occurring
1467
----------------------------------------------
B
WIP  
Bernard 已提交
1468

1469 1470 1471
It's important to mention backtracking behaviour is expected during a
``pip install`` process. What pip is trying to do is complicated - it is
working through potentially millions of package versions to identify the
B
Bernard 已提交
1472
compatible versions.
B
WIP  
Bernard 已提交
1473

1474 1475
There is no guaranteed solution to backtracking but you can reduce it -
here are a number of ways.
B
WIP  
Bernard 已提交
1476

1477 1478 1479
.. _1-allow-pip-to-complete-its-backtracking:

1. Allow pip to complete its backtracking
1480
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1481 1482 1483

In most cases, pip will complete the backtracking process successfully.
It is possible this could take a very long time to complete - this may
1484
not be your preferred option.
1485

1486
However, there is a possibility pip will not be able to find a set of
1487 1488 1489
compatible versions.

If you'd prefer not to wait, you can interrupt pip (ctrl and c) and use
B
Bernard 已提交
1490
:ref:`Constraints Files`: to reduce the number of package versions it tries.
1491 1492 1493

.. _2-reduce-the-versions-of-the-backtracking-package:

B
Bernard 已提交
1494
2. Reduce the number of versions pip will try to backtrack through
1495
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1496 1497 1498 1499 1500 1501 1502

If pip is backtracking more than you'd like, the next option is to
constrain the number of package versions it tries.

A first good candidate for this constraining is the package(s) it is
backtracking on (e.g. in the above example - ``cup``).

B
Bernard 已提交
1503
You could try:
1504

B
Bernard 已提交
1505
``pip install tea "cup > 3.13"``
B
WIP  
Bernard 已提交
1506

1507 1508
This will reduce the number of versions of ``cup`` it tries, and
possibly reduce the time pip takes to install.
B
WIP  
Bernard 已提交
1509

B
Bernard 已提交
1510
There is a possibility that if you're wrong (in this case an older
1511 1512
version would have worked) then you missed the chance to use it. This
can be trial and error.
B
WIP  
Bernard 已提交
1513

1514
.. _3-use-constraint-files-or-lockfiles:
B
WIP  
Bernard 已提交
1515

1516
3. Use constraint files or lockfiles
1517
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
B
WIP  
Bernard 已提交
1518

1519 1520 1521
This option is a progression of 2 above. It requires users to know how
to inspect:

B
Bernard Tyers 已提交
1522
-  the packages they're trying to install
1523 1524 1525
-  the package release frequency and compatibility policies
-  their release notes and changelogs from past versions

B
Bernard 已提交
1526 1527
During deployment, you can create a lockfile stating the exact package and
version number for for each dependency of that package. You can create this
1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538
with `pip-tools <https://github.com/jazzband/pip-tools/>`__.

This means the "work" is done once during development process, and so
will save users this work during deployment.

The pip team is not available to provide support in helping you create a
suitable constraints file.

.. _4-be-more-strict-on-package-dependencies-during-development:

4. Be more strict on package dependencies during development
1539
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1540

1541
For package maintainers during software development, give pip some help by
1542 1543 1544 1545 1546 1547 1548
creating constraint files for the dependency tree. This will reduce the
number of versions it will try.

Getting help
------------

If none of the suggestions above work for you, we recommend that you ask
B
Bernard 已提交
1549
for help. :ref:`Getting help`.
B
WIP  
Bernard 已提交
1550

1551 1552
.. _`Using pip from your program`:

1553
Using pip from your program
P
Pradyun Gedam 已提交
1554
===========================
1555

1556 1557 1558
As noted previously, pip is a command line program. While it is implemented in
Python, and so is available from your Python code via ``import pip``, you must
not use pip's internal APIs in this way. There are a number of reasons for this:
1559

1560 1561 1562 1563 1564
#. The pip code assumes that is in sole control of the global state of the
   program.
   pip manages things like the logging system configuration, or the values of
   the standard IO streams, without considering the possibility that user code
   might be affected.
1565

1566 1567
#. pip's code is *not* thread safe. If you were to run pip in a thread, there
   is no guarantee that either your code or pip's would work as you expect.
1568

1569 1570 1571 1572
#. pip assumes that once it has finished its work, the process will terminate.
   It doesn't need to handle the possibility that other code will continue to
   run after that point, so (for example) calling pip twice in the same process
   is likely to have issues.
1573

1574 1575 1576 1577 1578 1579 1580
This does not mean that the pip developers are opposed in principle to the idea
that pip could be used as a library - it's just that this isn't how it was
written, and it would be a lot of work to redesign the internals for use as a
library, handling all of the above issues, and designing a usable, robust and
stable API that we could guarantee would remain available across multiple
releases of pip. And we simply don't currently have the resources to even
consider such a task.
1581 1582

What this means in practice is that everything inside of pip is considered an
1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593
implementation detail. Even the fact that the import name is ``pip`` is subject
to change without notice. While we do try not to break things as much as
possible, all the internal APIs can change at any time, for any reason. It also
means that we generally *won't* fix issues that are a result of using pip in an
unsupported way.

It should also be noted that installing packages into ``sys.path`` in a running
Python process is something that should only be done with care. The import
system caches certain data, and installing new packages while a program is
running may not always behave as expected. In practice, there is rarely an
issue, but it is something to be aware of.
1594 1595 1596

Having said all of the above, it is worth covering the options available if you
decide that you do want to run pip from within your program. The most reliable
1597 1598
approach, and the one that is fully supported, is to run pip in a subprocess.
This is easily done using the standard ``subprocess`` module::
1599 1600 1601

  subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'my_package'])

1602 1603
If you want to process the output further, use one of the other APIs in the module.
We are using `freeze`_ here which outputs installed packages in requirements format.::
1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619

  reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])

If you don't want to use pip's command line functionality, but are rather
trying to implement code that works with Python packages, their metadata, or
PyPI, then you should consider other, supported, packages that offer this type
of ability. Some examples that you could consider include:

* ``packaging`` - Utilities to work with standard package metadata (versions,
  requirements, etc.)

* ``setuptools`` (specifically ``pkg_resources``) - Functions for querying what
  packages the user has installed on their system.

* ``distlib`` - Packaging and distribution utilities (including functions for
  interacting with PyPI).
1620

1621 1622
.. _changes-to-the-pip-dependency-resolver-in-20-2-2020:

1623 1624
.. _`Resolver changes 2020`:

1625
Changes to the pip dependency resolver in 20.3 (2020)
1626
=====================================================
1627

1628 1629 1630 1631 1632 1633
pip 20.3 has a new dependency resolver, on by default for Python 3
users. (pip 20.1 and 20.2 included pre-release versions of the new
dependency resolver, hidden behind optional user flags.) Read below
for a migration guide, how to invoke the legacy resolver, and the
deprecation timeline. We also made a `two-minute video explanation`_
you can watch.
1634 1635 1636 1637 1638 1639

We will continue to improve the pip dependency resolver in response to
testers' feedback. Please give us feedback through the `resolver
testing survey`_.

.. _`Migration guide for 2020 resolver changes`:
1640 1641 1642 1643

Watch out for
-------------

1644 1645
The big change in this release is to the pip dependency resolver
within pip.
1646 1647

Computers need to know the right order to install pieces of software
P
Pradyun Gedam 已提交
1648
("to install ``x``, you need to install ``y`` first"). So, when Python
1649 1650 1651 1652
programmers share software as packages, they have to precisely describe
those installation prerequisites, and pip needs to navigate tricky
situations where it's getting conflicting instructions. This new
dependency resolver will make pip better at handling that tricky
1653
logic, and make pip easier for you to use and troubleshoot.
1654 1655 1656 1657

The most significant changes to the resolver are:

* It will **reduce inconsistency**: it will *no longer install a
S
Sumana Harihareswara 已提交
1658 1659 1660 1661 1662 1663 1664 1665 1666 1667
  combination of packages that is mutually inconsistent*. In older
  versions of pip, it is possible for pip to install a package which
  does not satisfy the declared requirements of another installed
  package. For example, in pip 20.0, ``pip install "six<1.12"
  "virtualenv==20.0.2"`` does the wrong thing, “successfully” installing
  ``six==1.11``, even though ``virtualenv==20.0.2`` requires
  ``six>=1.12.0,<2`` (`defined here
  <https://github.com/pypa/virtualenv/blob/20.0.2/setup.cfg#L42-L50>`__).
  The new resolver, instead, outright rejects installing anything if it
  gets that input.
1668 1669

* It will be **stricter** - if you ask pip to install two packages with
S
Sumana Harihareswara 已提交
1670 1671
  incompatible requirements, it will refuse (rather than installing a
  broken combination, like it did in previous versions).
1672 1673 1674 1675 1676 1677

So, if you have been using workarounds to force pip to deal with
incompatible or inconsistent requirements combinations, now's a good
time to fix the underlying problem in the packages, because pip will
be stricter from here on out.

1678
This also means that, when you run a ``pip install`` command, pip only
1679 1680
considers the packages you are installing in that command, and **may
break already-installed packages**. It will not guarantee that your
1681 1682 1683
environment will be consistent all the time. If you ``pip install x``
and then ``pip install y``, it's possible that the version of ``y``
you get will be different than it would be if you had run ``pip
1684 1685
install x y`` in a single command. We are considering changing this
behavior (per :issue:`7744`) and would like your thoughts on what
1686 1687
pip's behavior should be; please answer `our survey on upgrades that
create conflicts`_.
1688

1689 1690 1691 1692 1693 1694
We are also changing our support for :ref:`Constraints Files`,
editable installs, and related functionality. We did a fairly
comprehensive overhaul and stripped constraints files down to being
purely a way to specify global (version) limits for packages, and so
some combinations that used to be allowed will now cause
errors. Specifically:
1695 1696 1697 1698

* Constraints don't override the existing requirements; they simply
  constrain what versions are visible as input to the resolver (see
  :issue:`9020`)
1699
* Providing an editable requirement (``-e .``) does not cause pip to
1700 1701 1702 1703
  ignore version specifiers or constraints (see :issue:`8076`), and if
  you have a conflict between a pinned requirement and a local
  directory then pip will indicate that it cannot find a version
  satisfying both (see :issue:`8307`)
1704
* Hash-checking mode requires that all requirements are specified as a
1705
  ``==`` match on a version and may not work well in combination with
1706
  constraints (see :issue:`9020` and :issue:`8792`)
1707 1708 1709
* If necessary to satisfy constraints, pip will happily reinstall
  packages, upgrading or downgrading, without needing any additional
  command-line options (see :issue:`8115` and :doc:`development/architecture/upgrade-options`)
S
Sumana Harihareswara 已提交
1710 1711 1712
* Unnamed requirements are not allowed as constraints (see :issue:`6628` and :issue:`8210`)
* Links are not allowed as constraints (see :issue:`8253`)
* Constraints cannot have extras (see :issue:`6628`)
1713

1714 1715 1716
Per our :ref:`Python 2 Support` policy, pip 20.3 users who are using
Python 2 will use the legacy resolver by default. Python 2 users
should upgrade to Python 3 as soon as possible, since in pip 21.0 in
1717
January 2021, pip dropped support for Python 2 altogether.
1718

1719

1720 1721
How to upgrade and migrate
--------------------------
1722

1723
1. **Install pip 20.3** with ``python -m pip install --upgrade pip``.
1724

S
Sumana Harihareswara 已提交
1725
2. **Validate your current environment** by running ``pip check``. This
1726 1727
   will report if you have any inconsistencies in your set of installed
   packages. Having a clean installation will make it much less likely
1728
   that you will hit issues with the new resolver (and may
1729 1730
   address hidden problems in your current environment!). If you run
   ``pip check`` and run into stuff you can’t figure out, please `ask
S
Sumana Harihareswara 已提交
1731
   for help in our issue tracker or chat <https://pip.pypa.io/>`__.
1732

1733
3. **Test the new version of pip**.
1734 1735 1736 1737 1738

   While we have tried to make sure that pip’s test suite covers as
   many cases as we can, we are very aware that there are people using
   pip with many different workflows and build processes, and we will
   not be able to cover all of those without your help.
1739 1740 1741

   -  If you use pip to install your software, try out the new resolver
      and let us know if it works for you with ``pip install``. Try:
S
Sumana Harihareswara 已提交
1742

1743 1744 1745 1746 1747
      - installing several packages simultaneously
      - re-creating an environment using a ``requirements.txt`` file
      - using ``pip install --force-reinstall`` to check whether
        it does what you think it should
      - using constraints files
1748
      - the "Setups to test with special attention" and "Examples to try" below
S
Sumana Harihareswara 已提交
1749

1750 1751 1752
   -  If you have a build pipeline that depends on pip installing your
      dependencies for you, check that the new resolver does what you
      need.
1753

1754 1755 1756
   -  Run your project’s CI (test suite, build process, etc.) using the
      new resolver, and let us know of any issues.
   -  If you have encountered resolver issues with pip in the past,
1757 1758 1759 1760 1761
      check whether the new resolver fixes them, and read :ref:`Fixing
      conflicting dependencies`. Also, let us know if the new resolver
      has issues with any workarounds you put in to address the
      current resolver’s limitations. We’ll need to ensure that people
      can transition off such workarounds smoothly.
1762 1763
   -  If you develop or support a tool that wraps pip or uses it to
      deliver part of your functionality, please test your integration
1764
      with pip 20.3.
1765

1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780
4. **Troubleshoot and try these workarounds if necessary.**

   -  If pip is taking longer to install packages, read
      :ref:`Dependency resolution backtracking` for ways to reduce the
      time pip spends backtracking due to dependency conflicts.
   -  If you don't want pip to actually resolve dependencies, use the
      ``--no-deps`` option. This is useful when you have a set of package
      versions that work together in reality, even though their metadata says
      that they conflict. For guidance on a long-term fix, read
      :ref:`Fixing conflicting dependencies`.
   -  If you run into resolution errors and need a workaround while you're
      fixing their root causes, you can choose the old resolver behavior using
      the flag ``--use-deprecated=legacy-resolver``. This will work until we
      release pip 21.0 (see
      :ref:`Deprecation timeline for 2020 resolver changes`).
1781

1782
5. **Please report bugs** through the `resolver testing survey`_.
1783 1784


1785 1786
Setups to test with special attention
-------------------------------------
1787

1788
*    Requirements files with 100+ packages
1789

1790
*    Installation workflows that involve multiple requirements files
1791

S
Sumana Harihareswara 已提交
1792
*    Requirements files that include hashes (:ref:`hash-checking mode`)
S
Sumana Harihareswara 已提交
1793
     or pinned dependencies (perhaps as output from ``pip-compile`` within
S
Sumana Harihareswara 已提交
1794 1795 1796
     ``pip-tools``)

*    Using :ref:`Constraints Files`
1797 1798 1799

*    Continuous integration/continuous deployment setups

1800
*    Installing from any kind of version control systems (i.e., Git, Subversion, Mercurial, or CVS), per :ref:`VCS Support`
1801 1802 1803

*    Installing from source code held in local directories

1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833
Examples to try
^^^^^^^^^^^^^^^

Install:

* `tensorflow`_
* ``hacking``
* ``pycodestyle``
* ``pandas``
* ``tablib``
* ``elasticsearch`` and ``requests`` together
* ``six`` and ``cherrypy`` together
* ``pip install flake8-import-order==0.17.1 flake8==3.5.0 --use-feature=2020-resolver``
* ``pip install tornado==5.0 sprockets.http==1.5.0 --use-feature=2020-resolver``

Try:

* ``pip install``
* ``pip uninstall``
* ``pip check``
* ``pip cache``


Tell us about
-------------

Specific things we'd love to get feedback on:

*    Cases where the new resolver produces the wrong result,
     obviously. We hope there won't be too many of these, but we'd like
1834
     to trap such bugs before we remove the legacy resolver.
1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845

*    Cases where the resolver produced an error when you believe it
     should have been able to work out what to do.

*    Cases where the resolver gives an error because there's a problem
     with your requirements, but you need better information to work out
     what's wrong.

*    If you have workarounds to address issues with the current resolver,
     does the new resolver let you remove those workarounds? Tell us!

1846
Please let us know through the `resolver testing survey`_.
1847

1848 1849
.. _`Deprecation timeline for 2020 resolver changes`:

1850 1851 1852 1853 1854 1855
Deprecation timeline
--------------------

We plan for the resolver changeover to proceed as follows, using
:ref:`Feature Flags` and following our :ref:`Release Cadence`:

1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867
*    pip 20.1: an alpha version of the new resolver was available,
     opt-in, using the optional flag
     ``--unstable-feature=resolver``. pip defaulted to legacy
     behavior.

*    pip 20.2: a beta of the new resolver was available, opt-in, using
     the flag ``--use-feature=2020-resolver``. pip defaulted to legacy
     behavior. Users of pip 20.2 who want pip to default to using the
     new resolver can run ``pip config set global.use-feature
     2020-resolver`` (for more on that and the alternate
     ``PIP_USE_FEATURE`` environment variable option, see `issue
     8661`_).
1868

1869 1870 1871
*    pip 20.3: pip defaults to the new resolver in Python 3 environments,
     but a user can opt-out and choose the old resolver behavior,
     using the flag ``--use-deprecated=legacy-resolver``. In Python 2
S
Sumana Harihareswara 已提交
1872
     environments, pip defaults to the old resolver, and the new one is
1873
     available using the flag ``--use-feature=2020-resolver``.
1874

1875 1876 1877 1878 1879
*    pip 21.0: pip uses new resolver by default, and the old resolver is
     no longer supported. It will be removed after a currently undecided
     amount of time, as the removal is dependent on pip's volunteer
     maintainers' availability. Python 2 support is removed per our
     :ref:`Python 2 Support` policy.
1880 1881 1882 1883 1884

Since this work will not change user-visible behavior described in the
pip documentation, this change is not covered by the :ref:`Deprecation
Policy`.

1885 1886 1887
Context and followup
--------------------

1888 1889
As discussed in `our announcement on the PSF blog`_, the pip team are
in the process of developing a new "dependency resolver" (the part of
1890
pip that works out what to install based on your requirements).
1891 1892

We're tracking our rollout in :issue:`6536` and you can watch for
1893 1894
announcements on the `low-traffic packaging announcements list`_ and
`the official Python blog`_.
1895

1896
.. _freeze: https://pip.pypa.io/en/latest/reference/pip_freeze/
1897
.. _resolver testing survey: https://tools.simplysecure.org/survey/index.php?r=survey/index&sid=989272&lang=en
1898
.. _issue 8661: https://github.com/pypa/pip/issues/8661
1899
.. _our announcement on the PSF blog: http://pyfound.blogspot.com/2020/03/new-pip-resolver-to-roll-out-this-year.html
1900
.. _two-minute video explanation: https://www.youtube.com/watch?v=B4GQCBBsuNU
1901
.. _tensorflow: https://pypi.org/project/tensorflow/
1902
.. _low-traffic packaging announcements list: https://mail.python.org/mailman3/lists/pypi-announce.python.org/
1903
.. _our survey on upgrades that create conflicts: https://docs.google.com/forms/d/e/1FAIpQLSeBkbhuIlSofXqCyhi3kGkLmtrpPOEBwr6iJA6SzHdxWKfqdA/viewform
1904
.. _the official Python blog: https://blog.python.org/
1905
.. _requests: https://requests.readthedocs.io/en/latest/user/authentication/#netrc-authentication
1906
.. _Python standard library: https://docs.python.org/3/library/netrc.html
1907
.. _Python Windows launcher: https://docs.python.org/3/using/windows.html#launcher