pip 抱怨依赖版本,但无论如何都会安装它们。为什么?

pip complains about dependency versions but installs them anyway. Why?

我有一个这样定义的需求文件:

requirements.txt

botocore==1.15.11
docutils==0.16

当我点击 pip install -r requirements.txt 时,我看到了这个错误:

botocore 1.15.11 has requirement docutils<0.16,>=0.10, but you'll have docutils 0.16 which is incompatible.

但是,当我点击 pip list 时,我看到的是输出:

botocore        1.15.11
docutils        0.16   
jmespath        0.10.0 
pip             18.1   
python-dateutil 2.8.1  
setuptools      40.6.2 
six             1.15.0 
urllib3         1.25.9 
wheel           0.34.2 

这表明这两个依赖项是按照 requirements.txt 文件中的定义安装的。如果这不是问题,为什么要抱怨呢?如果有问题,它们是如何安装的?

pip 的当前依赖项解决程序存在一些众所周知的问题(限制和错误)。一个新的(更好的)正在进行中。已经可以测试了。此答案及其链接中的更多详细信息:

话虽如此,这两个要求是不兼容的:

  • botocore==1.15.11
  • docutils==0.16

可以看出setup.cfg for botocore 1.15.11:

[bdist_wheel]
universal = 1

[metadata]
requires-dist =
    python-dateutil>=2.1,<3.0.0
    jmespath>=0.7.1,<1.0.0
    docutils>=0.10,<0.16
    urllib3>=1.20,<1.25.8; python_version=='3.4'
    urllib3>=1.20,<1.26; python_version!='3.4'

仍然可以指示 pip 安装这样的组合(一个被宣传为不兼容的组合)。并且 pip 会警告这种冲突,正如您在问题中所展示的那样,或者通过 运行 pip check (顺便说一句,据我所知,今天,已经使用较新的依赖项解析):

$ pip check
botocore 1.15.11 has requirement docutils<0.16,>=0.10, but you have docutils 0.16.

导入和执行的代码可能仍然可以正常工作,没有任何(明显的)问题。例如:可能 botocore 1.15.11 实际上与 docutils 0.16 并不完全不兼容。可能触发问题的代码路径未命中,或者限制 docutils<0.16 只是作为预防措施。