@@ -999,227 +999,6 @@ issue tracker`_ if you believe that your problem has exposed a bug in pip.
999
999
.. _"How do I ask a good question?" : https://stackoverflow.com/help/how-to-ask
1000
1000
.. _pip issue tracker : https://github.com/pypa/pip/issues
1001
1001
1002
- .. _`Dependency resolution backtracking` :
1003
-
1004
- Dependency resolution backtracking
1005
- ==================================
1006
-
1007
- Or more commonly known as *"Why does pip download multiple versions of
1008
- the same package over and over again during an install?" *.
1009
-
1010
- The purpose of this section is to provide explanation of why
1011
- backtracking happens, and practical suggestions to pip users who
1012
- encounter it during a ``pip install ``.
1013
-
1014
- What is backtracking?
1015
- ---------------------
1016
-
1017
- Backtracking is not a bug, or an unexpected behaviour. It is part of the
1018
- way pip's dependency resolution process works.
1019
-
1020
- During a pip install (e.g. ``pip install tea ``), pip needs to work out
1021
- the package's dependencies (e.g. ``spoon ``, ``hot-water ``, ``cup `` etc.), the
1022
- versions of each of these packages it needs to install. For each package
1023
- pip needs to decide which version is a good candidate to install.
1024
-
1025
- A "good candidate" means a version of each package that is compatible with all
1026
- the other package versions being installed at the same time.
1027
-
1028
- In the case where a package has a lot of versions, arriving at a good
1029
- candidate can take a lot of time. (The amount of time depends on the
1030
- package size, the number of versions pip must try, and other concerns.)
1031
-
1032
- How does backtracking work?
1033
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1034
-
1035
- When doing a pip install, pip starts by making assumptions about the
1036
- packages it needs to install. During the install process it needs to check these
1037
- assumptions as it goes along.
1038
-
1039
- When pip finds that an assumption is incorrect, it has to try another approach
1040
- (backtrack), which means discarding some of the work that has already been done,
1041
- and going back to choose another path.
1042
-
1043
- For example; The user requests ``pip install tea ``. ``tea `` has dependencies of
1044
- ``cup ``, ``hot-water ``, ``spoon `` amongst others.
1045
-
1046
- pip starts by installing a version of ``cup ``. If it finds out it isn’t
1047
- compatible (with the other package versions) it needs to “go back”
1048
- (backtrack) and download an older version.
1049
-
1050
- It then tries to install that version. If it is successful, it will continue
1051
- onto the next package. If not it will continue to backtrack until it finds a
1052
- compatible version.
1053
-
1054
- This backtrack behaviour can end in 2 ways - either 1) it will
1055
- successfully find a set of packages it can install (good news!), or 2) it will
1056
- eventually display a `resolution impossible <https://pip.pypa.io/en/latest/user_guide/#id35 >`__ error
1057
- message (not so good).
1058
-
1059
- If pip starts backtracking during dependency resolution, it does not
1060
- know how long it will backtrack, and how much computation would be
1061
- needed. For the user this means it can take a long time to complete.
1062
-
1063
- Why does backtracking occur?
1064
- ----------------------------
1065
-
1066
- With the release of the new resolver (:ref: `Resolver changes 2020 `), pip is now
1067
- more strict in the package versions it installs when a user runs a
1068
- ``pip install `` command.
1069
-
1070
- Pip needs to backtrack because initially, it doesn't have all the information it
1071
- needs to work out the correct set of packages. This is because package indexes
1072
- don't provide full package dependency information before you have downloaded
1073
- the package.
1074
-
1075
- This new resolver behaviour means that pip works harder to find out which
1076
- version of a package is a good candidate to install. It reduces the risk that
1077
- installing a new package will accidentally break an existing installed package,
1078
- and so reduces the risk that your environment gets messed up.
1079
-
1080
- What does this behaviour look like?
1081
- -----------------------------------
1082
-
1083
- Right now backtracking behaviour looks like this:
1084
-
1085
- ::
1086
-
1087
- $ pip install tea==1.9.8
1088
- Collecting tea==1.9.8
1089
- Downloading tea-1.9.8-py2.py3-none-any.whl (346 kB)
1090
- |████████████████████████████████| 346 kB 10.4 MB/s
1091
- Collecting spoon==2.27.0
1092
- Downloading spoon-2.27.0-py2.py3-none-any.whl (312 kB)
1093
- |████████████████████████████████| 312 kB 19.2 MB/s
1094
- Collecting hot-water>=0.1.9
1095
- Downloading hot-water-0.1.13-py3-none-any.whl (9.3 kB)
1096
- Collecting cup>=1.6.0
1097
- Downloading cup-3.22.0-py2.py3-none-any.whl (397 kB)
1098
- |████████████████████████████████| 397 kB 28.2 MB/s
1099
- INFO: pip is looking at multiple versions of this package to determine
1100
- which version is compatible with other requirements.
1101
- This could take a while.
1102
- Downloading cup-3.21.0-py2.py3-none-any.whl (395 kB)
1103
- |████████████████████████████████| 395 kB 27.0 MB/s
1104
- Downloading cup-3.20.0-py2.py3-none-any.whl (394 kB)
1105
- |████████████████████████████████| 394 kB 24.4 MB/s
1106
- Downloading cup-3.19.1-py2.py3-none-any.whl (394 kB)
1107
- |████████████████████████████████| 394 kB 21.3 MB/s
1108
- Downloading cup-3.19.0-py2.py3-none-any.whl (394 kB)
1109
- |████████████████████████████████| 394 kB 26.2 MB/s
1110
- Downloading cup-3.18.0-py2.py3-none-any.whl (393 kB)
1111
- |████████████████████████████████| 393 kB 22.1 MB/s
1112
- Downloading cup-3.17.0-py2.py3-none-any.whl (382 kB)
1113
- |████████████████████████████████| 382 kB 23.8 MB/s
1114
- Downloading cup-3.16.0-py2.py3-none-any.whl (376 kB)
1115
- |████████████████████████████████| 376 kB 27.5 MB/s
1116
- Downloading cup-3.15.1-py2.py3-none-any.whl (385 kB)
1117
- |████████████████████████████████| 385 kB 30.4 MB/s
1118
- INFO: pip is looking at multiple versions of this package to determine
1119
- which version is compatible with other requirements.
1120
- This could take a while.
1121
- Downloading cup-3.15.0-py2.py3-none-any.whl (378 kB)
1122
- |████████████████████████████████| 378 kB 21.4 MB/s
1123
- Downloading cup-3.14.0-py2.py3-none-any.whl (372 kB)
1124
- |████████████████████████████████| 372 kB 21.1 MB/s
1125
- Downloading cup-3.13.1-py2.py3-none-any.whl (381 kB)
1126
- |████████████████████████████████| 381 kB 21.8 MB/s
1127
- This is taking longer than usual. You might need to provide the
1128
- dependency resolver with stricter constraints to reduce runtime.
1129
- If you want to abort this run, you can press Ctrl + C to do so.
1130
- Downloading cup-3.13.0-py2.py3-none-any.whl (374 kB)
1131
-
1132
- In the above sample output, pip had to download multiple versions of
1133
- package ``cup `` - cup-3.22.0 to cup-3.13.0 - to find a version that will be
1134
- compatible with the other packages - ``spoon ``, ``hot-water ``, etc.
1135
-
1136
- These multiple ``Downloading cup-version `` lines show pip backtracking.
1137
-
1138
- Possible ways to reduce backtracking occurring
1139
- ----------------------------------------------
1140
-
1141
- It's important to mention backtracking behaviour is expected during a
1142
- ``pip install `` process. What pip is trying to do is complicated - it is
1143
- working through potentially millions of package versions to identify the
1144
- compatible versions.
1145
-
1146
- There is no guaranteed solution to backtracking but you can reduce it -
1147
- here are a number of ways.
1148
-
1149
- .. _1-allow-pip-to-complete-its-backtracking :
1150
-
1151
- 1. Allow pip to complete its backtracking
1152
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1153
-
1154
- In most cases, pip will complete the backtracking process successfully.
1155
- It is possible this could take a very long time to complete - this may
1156
- not be your preferred option.
1157
-
1158
- However, there is a possibility pip will not be able to find a set of
1159
- compatible versions.
1160
-
1161
- If you'd prefer not to wait, you can interrupt pip (ctrl and c) and use
1162
- :ref: `Constraints Files `: to reduce the number of package versions it tries.
1163
-
1164
- .. _2-reduce-the-versions-of-the-backtracking-package :
1165
-
1166
- 2. Reduce the number of versions pip will try to backtrack through
1167
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1168
-
1169
- If pip is backtracking more than you'd like, the next option is to
1170
- constrain the number of package versions it tries.
1171
-
1172
- A first good candidate for this constraining is the package(s) it is
1173
- backtracking on (e.g. in the above example - ``cup ``).
1174
-
1175
- You could try:
1176
-
1177
- ``pip install tea "cup > 3.13" ``
1178
-
1179
- This will reduce the number of versions of ``cup `` it tries, and
1180
- possibly reduce the time pip takes to install.
1181
-
1182
- There is a possibility that if you're wrong (in this case an older
1183
- version would have worked) then you missed the chance to use it. This
1184
- can be trial and error.
1185
-
1186
- .. _3-use-constraint-files-or-lockfiles :
1187
-
1188
- 3. Use constraint files or lockfiles
1189
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1190
-
1191
- This option is a progression of 2 above. It requires users to know how
1192
- to inspect:
1193
-
1194
- - the packages they're trying to install
1195
- - the package release frequency and compatibility policies
1196
- - their release notes and changelogs from past versions
1197
-
1198
- During deployment, you can create a lockfile stating the exact package and
1199
- version number for for each dependency of that package. You can create this
1200
- with `pip-tools <https://github.com/jazzband/pip-tools/ >`__.
1201
-
1202
- This means the "work" is done once during development process, and so
1203
- will save users this work during deployment.
1204
-
1205
- The pip team is not available to provide support in helping you create a
1206
- suitable constraints file.
1207
-
1208
- .. _4-be-more-strict-on-package-dependencies-during-development :
1209
-
1210
- 4. Be more strict on package dependencies during development
1211
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
-
1213
- For package maintainers during software development, give pip some help by
1214
- creating constraint files for the dependency tree. This will reduce the
1215
- number of versions it will try.
1216
-
1217
- Getting help
1218
- ------------
1219
-
1220
- If none of the suggestions above work for you, we recommend that you ask
1221
- for help. :ref: `Getting help `.
1222
-
1223
1002
.. _`Using pip from your program` :
1224
1003
1225
1004
Using pip from your program
0 commit comments