# 错误：无法安装 package-a 和 package-b，因为它们的依赖版本冲突。冲突原因：用户请求 package-a；package-b 依赖 package-a<2.0

- **ID:** `python/pip-dependency-resolver-backtracking-too-deep`
- **领域:** python
- **类别:** install_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

pip 的新解析器在传递依赖约束冲突时会执行穷举回溯。解析器会探索所有可能的版本组合，在大型依赖树或存在循环/深层嵌套约束时，可能耗时数分钟甚至无限挂起。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (70% 成功率)
   ```
   Use pip install --use-deprecated=legacy-resolver to fall back to the old non-backtracking resolver, which installs packages sequentially and may succeed with warnings.
   ```
2. **** (85% 成功率)
   ```
   Manually identify a compatible version set using pip install --dry-run -v and then pin exact versions in requirements.txt, e.g., package-a==1.2.3 and package-b==2.0.1.
   ```
3. **** (90% 成功率)
   ```
   Use pip-tools: pip-compile requirements.in to generate a fully pinned requirements.txt with compatible versions, then pip-sync.
   ```

## 无效尝试

- **** — Bypasses all dependency checks, leading to runtime ImportError or AttributeError when packages are actually missing or incompatible. (75% 失败率)
- **** — Latest versions often have their own new conflicts; resolver still backtracks, just with different constraints. (65% 失败率)
- **** — The resolver algorithm is already current; upgrading doesn't change the fundamental conflict in dependency metadata. (80% 失败率)
