The Python Oracle

How to pip install a package with min and max version range?

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Puzzle3

--

Chapters
00:00 Question
01:18 Accepted answer (Score 519)
01:44 Answer 2 (Score 166)
02:00 Answer 3 (Score 162)
02:41 Answer 4 (Score 7)
03:16 Thank you

--

Full question
https://stackoverflow.com/questions/8795...

Accepted answer links:
[requirements files]: https://pip.readthedocs.io/en/stable/ref...
[PEP 440]: https://www.python.org/dev/peps/pep-0440...

Answer 3 links:
[PEP 440]: https://www.python.org/dev/peps/pep-0440...

Answer 4 links:
[nok.github.io/pipdev]: https://nok.github.io/pipdev
[image]: https://i.stack.imgur.com/mbkzt.png
[nok.github.io/pipdev?spec=~=0.5.0&vers=0.6]: https://nok.github.io/pipdev?spe

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #pip #multipleversions

#avk47



ACCEPTED ANSWER

Score 597


You can do:

$ pip install "package>=0.2,<0.3"

And pip will look for the best match, assuming the version is at least 0.2, and less than 0.3.

This also applies to pip requirements files. See the full details on version specifiers in PEP 440.




ANSWER 2

Score 202


An elegant method would be to use the ~= compatible release operator according to PEP 440. In your case this would amount to:

package~=0.5.0

As an example, if the following versions exist, it would choose 0.5.9:

  • 0.5.0
  • 0.5.9
  • 0.6.0

For clarification, each two lines in a pair are equivalent:

~= 0.5.0
>= 0.5.0, == 0.5.*

~= 0.5
>= 0.5, == 0.*



ANSWER 3

Score 184


you can also use:

pip install package==0.5.*

which is more consistent and easy to read.




ANSWER 4

Score 19


nok.github.io/pipdev is an interactive tool for developers to test defined specifiers for version handling.

enter image description here

Related to the question: nok.github.io/pipdev?spec=~=0.5.0&vers=0.6