有时 pip 会抱怨冲突的依赖项,尽管没有实际的版本冲突,例如在这种情况下,即使从constraints.txt中完全删除
elastic-apm
的特定版本(只是将其保留在mypackage的setup.py中),它仍然失败,如下所示:
ERROR: Cannot install elastic-apm because these package versions have conflicting dependencies.
The conflict is caused by:
mypackage 1.2.3 depends on elastic-apm
The user requested (constraint) elastic-apm
To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
这是使用 pip 22.1.2 和 python 3.10 使用这样的命令(即使用轮子的本地文件夹,而不是 PyPI)
pip install -r requirements.txt -c constraints.txt --no-index --find-links LOCALDIR --no-cache-dir --isolated
为什么 pip 抱怨依赖冲突,而实际上根本没有请求特定的版本或范围,更不用说冲突的版本或范围?
事实证明,问题在于 LOCALDIR 不包含当前平台的轮子。
该文件夹包含此轮子,但不包含相应的 Windows 轮子(我们的错误)
elastic_apm-6.10.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
但是 pip 输出非常具有误导性 - 问题与冲突依赖关系无关,它只是找不到与必要平台匹配的包 - 如果 pip 告诉你这一点那就太好了。
我已经发布在 https://github.com/pypa/pip/issues/11009 看起来很相似。
使用自定义包(使用 pip 24.0)遇到类似的错误。结果是一个 python 版本问题,该包需要比安装它的 python 环境更高版本的 python。消息非常具有误导性。
ERROR: Cannot install <package> because these package versions have conflicting dependencies.
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies
The conflict is caused by:
The user requested <package>==0.8.0
The user requested (constraint) <package>==0.8.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 attempt to solve the dependency conflict