How to specify version ranges in install_requires (setuptools, distribute)

Viewed 23053

I want to make a package to depend the particular version range e.g. >= 0.5.0, < 0.7.0. Is it possible in install_requires option, and if so how should it be?

5 Answers

The notation mentioned in OP's question, >= 0.5.0, < 0.7.0, already works.

And, since many (if not most) of the libraries would already use semantic versioning, so by definition you can define your dependency as A>=1,<2, as explained here. And they even implemented an even simpler syntax for it, A~=X.Y, meaning it requires at least release X.Y, but also allows any later release with a matching MAJOR version.

Another way to it is to use wildcards.

This does not apply to >= 0.5.0, < 0.7.0, but in case you decide that all maintenance releases should be supported (e.g. 0.5.0 to 0.5.x), you can use

== 0.5.*

e.g. docutils == 0.3.*

The answer for OP question including the install_requires would be looks like this:

setuptools.setup(
    ...
    install_requires=['package>=0.5.0,< 0.7.0']
    ...
    )

Other example with extra rejecting certain version based on others answer:

setuptools.setup(
    ...
    install_requires=['package>=1.4.2,<1.9,!=1.5.*,!=1.6.*']
    ...
    )
Related