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

python package versioning
pip version specification
python pin to major version
python-dev version
pip version identifiers
python package requirements txt
pip install -e
pip install --target

I'm wondering if there's any way to tell pip, specifically in a requirements file, to install a package with both a minimum version (pip install package>=0.2) and a maximum version which should never be installed (theoretical api: pip install package<0.3).

I ask because I am using a third party library that's in active development. I'd like my pip requirements file to specify that it should always install the most recent minor release of the 0.5.x branch, but I don't want pip to ever try to install any newer major versions (like 0.6.x) since the API is different. This is important because even though the 0.6.x branch is available, the devs are still releasing patches and bugfixes to the 0.5.x branch, so I don't want to use a static package==0.5.9 line in my requirements file.

Is there any way to do that?

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.

How to pip install a package with min and max version range?, 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  $ 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 .

you can also use:

pip install package==0.5.*

which is more consistent and easy to read.

How to pip install a package with min and max version range?, to tell pip, specifically in a requirements file, to install a package with both a minimum version ( pip install package>=0.2 ) and a maximum  Exclude certain dependency version ranges in setuptools/pip. How can I exclude a complete range? How to pip install a package with min and max version range? 587.

install_requires vs requirements files, I'm wondering if there's any way to tell pip, specifically in a requirements file, to install a package with both a minimum version (pip install package>=0.2) and a  Is there anyway to modify common.txt file so running pip install installs the latest version? I am asking because this file is going to be used by a couple of developers and if they have for example version 0.5.3 of that package already, it would'nt upgrade it and there are lots of packages needing upgrade.

pip install, way to tell pip, specifically in a requirements file, to install a package with both a minimum version ( pip install package>=0.2 ) and a maximum version which  – all the available versions will be printed without actually downloading or installing any additional packages. For pip < 9.0 use. pip install pylibmc==blork where blork can be any string that is not a valid version number.

jazzband/pip-tools: A set of tools to keep your pinned , with both a minimum version (pip install package>=0.2) and a maximum version which should never be installed (theoretical api: pip install package<0.3). I work with python 2.7.8 and can't change the version of python because it affect other important programs. Continuously to Unzip zip files in folders and subfolders with python i don't know how to install "pip install pathlib". Any help would be great.

pip sometimes installs release candidates instead of stable releases , When the project is installed by pip, this is the specification that is used to install best practice to use install_requires to pin dependencies to specific versions, or to “Concrete”, i.e. associated with a particular index or directory of packages. Great answer, but what confuses me is that the comma sometimes means or and sometimes and: the list of exact version specs clearly says '1.1 or 1.2 or ' and combining >= 0.3, >=0.2 to just >=0.2 only makes sense that way. But >= 0.3, <=0.5 or your paragraph about contradicting version specs need the comma to signify and. – zpea Jul 21 '12 at 22:34

Comments
  • Dead link. Official documentation here.
  • For the record, I think "package>=0.2,<=0.3" doesn't make a lot of sense: when would you be okay with both 0.2 and 0.3.0, but not with any of 0.3's bugfix releases? I think "package>=0.2,<0.3" is a much better example, because it reflects the common case of saying: "please give me the latest bugfix release of the current minor version, but don't automatically upgrade me to the next minor version, because I would like to do that explicitly, making sure that there are no functional changes affecting me."
  • If you like this answer, you'll love Mortiz answer right down below! Be sure to check it out, ~=0.2 is (imho) a better solution than this.
  • @BradRoot It's really unclear what ~=0.2.1 would do, for example. Being explicit as in >=0.2,<0.3 is a good thing because it's really clear what's happening.
  • @Acumenus someone who understands the properties of the requirement format and how versioning works wouldn't write ~=0.2.1 in a requirements file. That's user error, not a disadvantage of the ~= prefix.
  • This is a much better way to manage requirements.txt IMO. Using package==1.* instead of package>=1.2 prevents pip from installing major version 2+ for the package, which is desirable since major version changes are often backwards incompatible.
  • Note, This doesn't upgrade an existing package. e.g. if you have 0.5.1 installed, but 0.5.2 is latest, and you run install 0.5.* it will say "already satisfied" and leave you with 0.5.1. Adding --upgrade solves it.
  • How would you use this for truncated versions? E.g. if there's a 2.2 and a planned future 2.2.1, will ~=2.2.* match 2.2 despite there not being a tertiary number?
  • @Mike'Pomax'Kamermans You should use ~=2.2.0 in that case(* operator will not work if you're using ~=). 2.2 and 2.2.0 (and 2.2.0.0, and so on) are internally handled as same thing when it comes to installing packages.
  • It is extremely unclear how this works for nested version numbering, e.g. ~=1.2.3. It is a lot more explicit and clearer to use the multi-clause form instead.
  • By far the clearest is == 1.*. Couldn't be clearer! "Latest possible 1.x version". And if the package follows semantic versioning, ALL 1.x versions WILL be compatible with each other, since only major versions (2.x, 3.x) are allowed to break APIs.