pip wheel 收集了一个包的 2 个版本,然后 pip install 发生冲突

Pip wheel collects 2 versions of a package then pip install gets a conflict

我们使用一个管道,首先使用 pip wheel 收集项目中需要的所有包,然后它创建一个 docker 图像,调用收集到的 pip install轮子。

我遇到的问题是调用 pip wheel 时,pip 正在收集一个包的 2 个不同版本。一旦有新版本的软件包可用,这种情况就会开始发生。

该项目需要一个内部库 ecs-deployer==10.1.2,而该库又具有以下形式的要求:elb-listener>=3.2.1+25,<4

带有详细选项的 pip wheel 的相关输出说:

Collecting elb-listener>=3.2.1+25,<4                                                                                                                                                                                             
Created temporary directory: /tmp/pip-unpack-zr930807                                                                                                
File was already downloaded /home/user/path/dist/elb_listener-3.2.2+26-py3-none-any.whl             
Added elb-listener>=3.2.1+25,<4 from https://internal-repository.com/path/elb_listener/3.2.2%2B26/elb_listener-3.2.2%2B26-py3-none-any.whl#md5=foo (from ecs-deployer==10.1.2->service==1.0.0) to build tracker '/tmp/pip-req-tracker-1tz9t5ls'
Removed elb-listener>=3.2.1+25,<4 from https://internal-repository.com/path/elb_listener/3.2.2%2B26/elb_listener-3.2.2%2B26-py3-none-any.whl#md5=blabla (from ecs-deployer==10.1.2->service==1.0.0) to build tracker '/tmp/pip-req-tracker-1tz9t5ls'

还有:

Collecting elb-listener>=3.2.1+25,<4                                                                                                                                                                                             
Created temporary directory: /tmp/pip-unpack-yfnxim_u                                                                                                
File was already downloaded /home/user/path/dist/elb_listener-3.2.3+27-py3-none-any.whl             
Added elb-listener>=3.2.1+25,<4 from https://internal-repository.com/path/elb_listener/3.2.3%2B27/elb_listener-3.2.3%2B27-py3-none-any.whl#md5=bar (from ecs-deployer==10.1.2->service==1.0.0) to build tracker '/tmp/pip-req-tracker-1tz9t5ls'

然后当调用 pip 安装时,我得到这个:

ERROR: Cannot install elb-listener 3.2.2+26 (from /opt/elb_listener-3.2.2+26-py3-none-any.whl) and cad-aws-elb-listener-target-group-builder 3.2.3+27 (from /opt/elb_listener-3.2.3+27-py3-none-any.whl) because these package versions have conflicting dependencies.
The conflict is caused by:
    The user requested elb-listener 3.2.2+26 (from /opt/elb_listener-3.2.2+26-py3-none-any.whl)
    The user requested elb-listener 3.2.3+27 (from /opt/elb_listener-3.2.3+27-py3-none-any.whl)

我们使用带有选项 --use-feature=2020-resolver

的 pip 20.2.3

pip wheel收集同一个包的多个版本是否正常?

如果是这样,我能否以任何方式指示 pip wheel 仅收集其中一个版本或 pip install 仅使用最新版本?

如果不行,请问有什么办法可以解决这个问题?我想将要求更改为 elb-listener>=3.2.1+27,<4 会解决它,但我们无法直接访问该库,其他团队需要一段时间才能更改它。

据我所知,“本地版本标识符”如 3.2.1+25 与平常相去甚远,显然它们不打算在任何地方使用 public(如 PyPI ),这可能就是这里所有麻烦的原因。我真的不确定 Python 打包工具对它们的支持有多好,也许它们混淆了依赖项解析。

Local version identifiers SHOULD NOT be used when publishing upstream projects to a public index server, but MAY be used to identify private builds created directly from the project source. Local version identifiers SHOULD be used by downstream projects when releasing a version that is API compatible with the version of the upstream project identified by the public version identifier, but contains additional changes (such as bug fixes). As the Python Package Index is intended solely for indexing and hosting upstream projects, it MUST NOT allow the use of local version identifiers.

-- "Local version identifiers" section of _PEP 440

根据@sinoroc 评论,将 python 升级到 3.10 并将 pip 版本升级到 21.2.4 解决了这个特定问题。