@@ -39,7 +39,7 @@ of how dependency resolution for Python packages works.
39
39
The user requests `pip install tea`. The package `tea` declares a dependency on
40
40
`hot-water`, `spoon`, `cup`, amongst others.
41
41
42
- pip starts by picking the most recent version of `tea` and get the list of
42
+ pip starts by picking the most recent version of `tea` and gets the list of
43
43
dependencies of that version of `tea`. It will then repeat the process for
44
44
those packages, picking the most recent version of `spoon` and then `cup`. Now,
45
45
pip notices that the version of `cup` it has chosen is not compatible with the
@@ -298,7 +298,70 @@ In this situation, you could consider:
298
298
- Refactoring your project to reduce the number of dependencies (for
299
299
example, by breaking up a monolithic code base into smaller pieces).
300
300
301
- ### Getting help
301
+ ## Handling Resolution Too Deep Errors
302
+
303
+ Sometimes pip's dependency resolver may exceed its search depth and terminate
304
+ with a ` ResolutionTooDeepError ` exception. This typically occurs when the
305
+ dependency graph is extremely complex or when there are too many package
306
+ versions to evaluate.
307
+
308
+ To address this error, consider the following strategies:
309
+
310
+ ### Specify Reasonable Lower Bounds
311
+
312
+ By setting a higher lower bound for your dependencies, you narrow the search
313
+ space. This excludes older versions that might trigger excessive backtracking.
314
+ For example:
315
+
316
+ ``` {pip-cli}
317
+ $ pip install "package_coffee>=0.44.0" "package_tea>=4.0.0"
318
+ ```
319
+
320
+ ### Use the ` --upgrade ` Flag
321
+
322
+ The ` --upgrade ` flag directs pip to ignore already installed versions and
323
+ search for the latest versions that meet your requirements. This can help
324
+ avoid unnecessary resolution paths:
325
+
326
+ ``` {pip-cli}
327
+ $ pip install --upgrade package_coffee package_tea
328
+ ```
329
+
330
+ ### Utilize Constraint Files
331
+
332
+ If you need to impose additional version restrictions on transitive
333
+ dependencies (dependencies of dependencies), consider using a constraint
334
+ file. A constraint file specifies version limits for packages that are
335
+ indirectly required. For example:
336
+
337
+ ```
338
+ # constraints.txt
339
+ indirect_dependency>=2.0.0
340
+ ```
341
+
342
+ Then install your packages with:
343
+
344
+ ``` {pip-cli}
345
+ $ pip install --constraint constraints.txt package_coffee package_tea
346
+ ```
347
+
348
+ ### Use Upper Bounds Sparingly
349
+
350
+ Although upper bounds are generally discouraged because they can complicate
351
+ dependency management, they may be necessary when certain versions are known
352
+ to cause conflicts. Use them cautiously—for example:
353
+
354
+ ``` {pip-cli}
355
+ $ pip install "package_coffee>=0.44.0,<1.0.0" "package_tea>=4.0.0"
356
+ ```
357
+
358
+ ### Report ResolutionTooDeep Errors
359
+
360
+ If you encounter a ` ResolutionTooDeep ` error consider reporting it, to help
361
+ the pip team have real world examples to test against, at the dedicated
362
+ [ pip issue] ( https://github.com/pypa/pip/issues/13281 ) .
363
+
364
+ ## Getting help
302
365
303
366
If none of the suggestions above work for you, we recommend that you ask
304
367
for help on:
0 commit comments