在Python pip冻结中,三等号和ubuntu2是什么?

在我的AWS Ubuntu 14.04实例上,我刚刚执行了一个pip冻结> requirements.txt给了我一个文件,其中还包括以下两行:

python-apt===0.9.3.5ubuntu2
python-debian===0.1.21-nmu2ubuntu2

当我然后使用此文件在另一个AWS Ubuntu 14.04实例上执行pip install -r requirements.txt时,我得到以下回溯:

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 262, in run
    for req in parse_requirements(filename, finder=finder, options=options, session=session):
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1632, in parse_requirements
    req = InstallRequirement.from_line(line, comes_from, prereleases=getattr(options, "pre", None))
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 173, in from_line
    return cls(req, comes_from, url=url, prereleases=prereleases)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 71, in __init__
    req = pkg_resources.Requirement.parse(req)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2667, in parse
    reqs = list(parse_requirements(s))
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2605, in parse_requirements
    line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version spec")
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2573, in scan_list
    raise ValueError("Expected "+item_name+" in",line,"at",line[p:])
ValueError: ('Expected version spec in', 'python-apt===0.9.3.5ubuntu2', 'at', '0.9.3.5ubuntu2')

我想知道这里有两件事:

>为什么pip冻结在版本末尾使用ubuntu2?
>为什么pip冻结使用===而不是==?

[编辑]

还有一个问题:

>为什么pip在另一台机器上不接受===和ubuntu2(我分别试过)?

最佳答案 ===是 arbitrary equality clause,在PEP-0440中定义:

Arbitrary equality comparisons are simple string equality operations
which do not take into account any of the semantic information such as
zero padding or local versions. This operator also does not support
prefix matching as the == operator does.

The primary use case for arbitrary equality is to allow for specifying
a version which cannot otherwise be represented by this PEP. This
operator is special and acts as an escape hatch to allow someone using
a tool which implements this PEP to still install a legacy version
which is otherwise incompatible with this PEP.

An example would be ===foobar which would match a version of foobar .

This operator may also be used to explicitly require an unpatched
version of a project such as ===1.0 which would not match for a
version 1.0+downstream1 .

Use of this operator is heavily discouraged and tooling MAY display a
warning when it is used.

您应该在目标计算机上升级您的pip版本(pip install –upgrade pip),它不应该显示错误消息.

点赞