错误:无法安装 package-a[extra1,extra2]==1.0 和 package-b==2.0,因为这些包版本存在依赖冲突。冲突由以下原因引起:package-a 1.0 依赖 package-c>=3.0,而 package-b 2.0 依赖 package-c<3.0。
ERROR: Cannot install package-a[extra1,extra2]==1.0 and package-b==2.0 because these package versions have conflicting dependencies. The conflict is caused by: package-a 1.0 depends on package-c>=3.0 and package-b 2.0 depends on package-c<3.0.
ID: pip/dependency-conflict-with-extras
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| pip 23.2 | active | — | — | — |
| pip 24.1 | active | — | — | — |
| pip 24.2 | active | — | — | — |
根因分析
两个请求的包对共享依赖项有互斥的版本约束,pip 的解析器无法找到同时满足两个约束的共享依赖版本。
English
Two requested packages have mutually exclusive version constraints on a shared dependency, and pip's resolver cannot find a version of the shared dependency that satisfies both constraints simultaneously.
官方文档
https://pip.pypa.io/en/stable/topics/dependency-resolution/#conflicting-dependencies解决方案
-
安装旧版本的 package-a,该版本依赖于 package-c<3.0:pip install 'package-a[extra1,extra2]<1.0' package-b==2.0
-
使用虚拟环境,安装同时满足两个条件的 package-c 版本(例如 package-c==2.99),然后不安装依赖地安装包:pip install package-c==2.99 && pip install --no-deps package-a[extra1,extra2]==1.0 package-b==2.0
-
联系包维护者放宽版本约束,或使用解决冲突的分支。
无效尝试
常见但无效的做法:
-
Force install both packages with --no-deps to skip dependency resolution
85% 失败
While this allows installation, the conflicting dependency package-c will be missing or have an incompatible version, causing runtime ImportError or AttributeError.
-
Upgrade pip to the latest version hoping the resolver improves
70% 失败
The conflict is fundamental to the version constraints; no resolver can satisfy mutually exclusive requirements unless constraints are relaxed.