How do I pip install the latest patch number of a package?
If you already have a compatible version of package
installed, the accepted answer by user3850 will not upgrade to the latest patch (in my experience, that is).
For example I have django 1.9.8
installed and want to upgrade to the latest patch, which is 1.9.13
, but pip install django~=1.9.0
(or pip install django~=1.9
) tells me requirement already satisfied
(using pip 18.0).
So, in this case we need to add --upgrade
. There are two options that work for me:
pip install django~=1.9.0 --upgrade
and one that I find more readable (based on this answer):
pip install django==1.9.* --upgrade
If using the first option (~=
) make sure to include the "micro" version number (as in "major.minor.micro"). For example, pip install django~=1.9.0 --upgrade
upgrades to 1.9.13
, as desired, but pip install django~=1.9 --upgrade
(i.e. without the .0
) upgrades to 1.11.15
instead.
Note: the lack of a lower bound, e.g. =>1.9.8
, in option 2. should not be an issue because upgrade would give us the latest match anyway.
pip
supports the ~=
version specifier for specifying the version number, so
pip install package~=1.10.0
would install version 1.10.9 if that is the latest patch level of that package.
There are more detailed explanations and comparisons to other methods of achieving the same results in the docs, for example:
~= 2.2.0
is equivalent to
>= 2.2.0, == 2.2.*