错误:无法安装 package-a==1.0 和 package-b==2.0,因为这些软件包版本存在冲突的依赖关系。冲突原因是:package-a 1.0 依赖 package-c[extra1]>=3.0,而 package-b 2.0 依赖 package-c[extra2]>=3.0。要解决此问题,您可以尝试:1. 放宽指定的软件包版本范围。2. 删除软件包版本以允许 pip 尝试解决依赖冲突。
ERROR: Cannot install package-a==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[extra1]>=3.0 and package-b 2.0 depends on package-c[extra2]>=3.0. To fix this, you could try to: 1. loosen the range of package versions you've specified. 2. remove package versions to allow pip to attempt to solve the dependency conflict.
ID: pip/dependency-conflict-with-extras-syntax
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| pip 23.0 | active | — | — | — |
| pip 23.3 | active | — | — | — |
| pip 24.1 | active | — | — | — |
根因分析
两个软件包需要同一个依赖包的不同 extras,而 pip 的解析器无法在没有组合 extra 的情况下同时安装这两个 extras,导致依赖冲突。
English
Two packages require different extras of the same dependency package, and pip's resolver cannot install both extras simultaneously without a combined extra, leading to a dependency conflict.
官方文档
https://pip.pypa.io/en/stable/topics/dependency-resolution/解决方案
-
使用组合说明符安装包含两个 extras 的冲突依赖:pip install 'package-c[extra1,extra2]>=3.0',然后安装冲突的软件包而不固定版本:pip install package-a package-b
-
创建虚拟环境并使用 pip-compile(来自 pip-tools)生成包含两个 extras 的已解析 requirements.txt:pip-compile --extra=extra1 --extra=extra2 requirements.in
-
联系 package-c 的维护者,请求一个包含 extra1 和 extra2 的组合 extra,或使用合并了它们的 fork。
无效尝试
常见但无效的做法:
-
Installing package-c[extra1,extra2] manually before the conflicting packages
85% 失败
Pip's resolver still sees the conflict because it evaluates the full dependency tree; manual pre-installation does not override the resolver's logic and may lead to an inconsistent state.
-
Using --ignore-dependencies flag to force installation
90% 失败
This can cause runtime import errors or broken functionality because the required extras are not installed correctly.
-
Downgrading both packages to versions that don't use extras
60% 失败
Such versions may not exist or may introduce other security or compatibility issues.