In requirements.txt, what does tilde equals (~=) mean?

James Hiew picture James Hiew · Sep 20, 2016 · Viewed 27.5k times · Source

In the requirements.txt for a Python library I am using, one of the requirements is specified like:

mock-django~=0.6.10

What does ~= mean?

Answer

Maxime Lorant picture Maxime Lorant · Sep 20, 2016

It means it will select the latest version of the package, greater than or equal to 0.6.10, but still in the 0.6.* version, so it won't download 0.7.0 for example. It ensures you will get security fixes but keep backward-compatibility, if the package maintainer respects the semantic versioning (which states that breaking changes should occur only in major versions).

Or, as said by PEP 440:

For a given release identifier V.N , the compatible release clause is approximately equivalent to the pair of comparison clauses:

>= V.N, == V.*