Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are triple equal signs and ubuntu2 in Python pip freeze?

On my AWS Ubuntu 14.04 instance I just did a pip freeze > requirements.txt which gave me a file which also includes the following two lines:

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

When I then use this file to do a pip install -r requirements.txt on a another AWS Ubuntu 14.04 instance I get the following traceback:

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')

I wonder about two things here:

  1. Why does pip freeze use the ubuntu2 at the end of the version?
  2. Why does pip freeze use the === instead of ==?

[EDIT]

And one more question:

  1. Why does pip on the other machine not accept the === and the ubuntu2 (I tried both separately)?
like image 725
kramer65 Avatar asked Dec 23 '15 10:12

kramer65


People also ask

What does triple equal sign mean in Python?

Identical Operator === The comparison operator called as the Identical operator is the triple equal sign “===”. This operator allows for a much stricter comparison between the given variables or values. This operator returns true if both variable contains same information and same data types otherwise return false.

What is pip freeze in Python?

pip freeze only installs those packages which were installed using the pip install command. However, pip is not the only python package manager. We can also use chocolatey, conda, setuptools etc. and they are not supported by pip freeze so we would have to write them manually in the requirements. txt file.

How do you freeze a requirement in pip?

The most common command is pip freeze > requirements. txt , which records an environment's current package list into requirements. txt. If you want to install the dependencies in a virtual environment, create and activate that environment first, then use the Install from requirements.

What is Python freeze?

“Freezing” your code is creating a single-file executable file to distribute to end-users, that contains all of your application code as well as the Python interpreter. Applications such as 'Dropbox', 'Eve Online', 'Civilization IV', and BitTorrent clients do this.


1 Answers

The === is the arbitrary equality clause and is defined in 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.

You should upgrade your version of pip on the target machine (pip install --upgrade pip) and it should not display the error message.

like image 117
Burhan Khalid Avatar answered Sep 28 '22 05:09

Burhan Khalid