Search code examples
pythonpipsetuptools

Why pip install colorama~=0.3 installs colorama-0.4.0


I have trouble installing my project which depends on Colorama. In the setup.py, I specified:

'colorama ~= 0.3'

But I’m surprised to see that the version 0.4 is installed (this version is new).

How to reproduce? Create and activate a virtualenv and run:

pip install colorama~=0.3

And then look at the logs or run:

pip list

What’s wrong with the ~= operator?

note: I'm using pip v18.1 and setuptools v40.4.3


Solution

  • The operator ~= means "compatible release". When using semantic versioning a compatible version is such that the first number in the sequence is the same (number 0 in this case).

    From the link above:

    Given a version number MAJOR.MINOR.PATCH, increment the:

    MAJOR version when you make incompatible API changes, MINOR version when you add functionality in a backwards-compatible manner, and PATCH version when you make backwards-compatible bug fixes.