10aday › Version Constraint Checker › pip ~= and version specifiers
~= “compatible release” and PEP 440 version specifiers: exact ranges for requirements.txtShort answer: ~=1.4.2 means ≥1.4.2 and ==1.4.* (so <1.5.0); ~=1.4 means ≥1.4 and ==1.* (so <2.0). The last number you wrote may increase.
~=1 is invalid: compatible release needs at least two numbers. ==1.4 is exact (it matches 1.4.0 too, because PEP 440 pads with zeros),
==1.4.* is the wildcard, and a version without an operator (requests 2.31) is not a valid specifier. Multiple clauses are joined with a comma, and there is no “or”.
Have a constraint and a list of versions? Paste them into the Version Constraint Checker: it shows, side by side, what npm, Cargo, Composer, pip and RubyGems accept.
Each cell shows how that tool spells it, then the range it allows. Highlighted: where the meanings differ.
| Constraint | pip | RubyGems | |
|---|---|---|---|
~=1.4.2 | ~=1.4.2≥1.4.2 <1.5.0 | ~> 1.4.2≥1.4.2 <1.5.0 | try it |
~=1.4 | ~=1.4≥1.4.0 <2.0.0 | ~> 1.4≥1.4.0 <2.0.0 | try it |
~=1pip needs two numbers | ~=1not valid | ~> 1≥1.0.0 <2.0.0 | try it |
~=0.2no special 0.x rule | ~=0.2≥0.2.0 <1.0.0 | ~> 0.2≥0.2.0 <1.0.0 | try it |
==1.4.*RubyGems: use ~> 1.4.0 | ≥1.4.0 <1.5.0 | not valid | try it |
==1.* | ≥1.0.0 <2.0.0 | not valid | try it |
==1.4 | ==1.4exactly 1.4.0 | = 1.4exactly 1.4.0 | try it |
1.4 (bare)pip requires an operator | not valid | exactly 1.4.0 | try it |
!=1.4.1 | not 1.4.1 | not 1.4.1 | try it |
>1.4 | >1.4.0 | >1.4.0 | try it |
<=2.3 | ≤2.3.0 | ≤2.3.0 | try it |
>=1.4, <2 | ≥1.4.0 <2.0.0 | ≥1.4.0 <2.0.0 | try it |
>=1.0, <2.0, !=1.4.1 | ≥1.0.0 <2.0.0, not 1.4.1 | ≥1.0.0 <2.0.0, not 1.4.1 | try it |
Ranges shown for final releases. pip skips pre-releases (1.5.0rc1) unless the specifier names one or you pass --pre;
post-releases (1.4.2.post1) and local versions have their own rules. The checker handles pre-releases.
| Constraint | pip | npm | Composer | |
|---|---|---|---|---|
~=1.4npm reads ~= as its own ~ | ≥1.4.0 <2.0.0 | ≥1.4.0 <1.5.0 | not valid | try it |
>=1.4, <2npm: use a space | ≥1.4.0 <2.0.0 | not valid | ≥1.4.0 <2.0.0 | try it |
~=1.4 (any 1.x from 1.4) is the usual choice; ~=1.4.2 allows bug-fix releases only.^1.4 is a Poetry extension, rejected by pip and by the [project] table of pyproject.toml.~= is your ~>, except that it needs two numbers. Coming from npm? See ~> vs ~= vs ~.It is the PEP 440 “compatible release” operator. ~=1.4.2 = ≥1.4.2, ==1.4.* (<1.5.0). ~=1.4 = ≥1.4, ==1.* (<2.0). It equals Ruby's ~> and Composer's ~, but not npm's ~ when you write two numbers.
==1.4 matches only 1.4 (and 1.4.0, which is the same version under PEP 440). ==1.4.* matches every 1.4.x release: ≥1.4.0 <1.5.0.
PEP 440 requires at least two release numbers with ~=, because it drops the last one to build the prefix. Use ~=1.0 (≥1.0, <2.0) or ==1.* instead.
Join clauses with a comma: >=1.0, <2.0, !=1.4.1. Every clause must hold. pip has no “or” operator; || is rejected.
^ and ~ into [project] dependencies (Poetry 2, uv)