错误:无法安装 foo==1.0 和 bar==2.0,因为这些包版本的依赖存在冲突。冲突原因:foo 1.0 依赖 baz<2;bar 2.0 依赖 baz>=2
ERROR: Cannot install foo==1.0 and bar==2.0 because these package versions have conflicting dependencies. The conflict is caused by: foo 1.0 depends on baz<2; bar 2.0 depends on baz>=2
ID: python/pip-resolver-conflict-incompatible
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
新版 pip 解析器(pip >= 20.3)执行完整回溯,发现没有任何一组版本能同时满足所有约束。两个依赖对同一个共享包要求互斥的版本范围。
English
The new pip resolver (pip >= 20.3) performs full backtracking and detects that no single set of versions satisfies all constraints. Two dependencies require mutually exclusive ranges of a shared package.
解决方案
-
85% 成功率
pip install 'foo<1.0' 'bar>=2' # try ranges # or use pip-tools to resolve: pip install pip-tools pip-compile requirements.in
-
75% 成功率
python -m venv venv_foo && venv_foo/bin/pip install foo python -m venv venv_bar && venv_bar/bin/pip install bar # call via subprocess from a coordinating process
无效尝试
常见但无效的做法:
-
85% 失败
The legacy resolver just picks one arbitrarily and installs an inconsistent environment that breaks at runtime with ImportError or AttributeError.
-
80% 失败
Skips dependency installation entirely, leaving baz missing or at the wrong version so imports fail.