Installing specific package version with pip

Better Stack Team
Updated on February 3, 2023

To install a specific version of a package with pip, you can use the == operator followed by the desired version number. For example:

 
pip install package_name==1.0.4

This will install version 1.0.4 of the package. If you want to install a version that is compatible with a certain version of Python, you can specify the Python version using the python keyword followed by the version number. For example:

 
pip install package_name==1.0.4 python==3.6

This will install version 1.0.4 of the package and ensure that it is compatible with Python 3.6.

You can also use the > and < operators to specify a minimum or maximum version number, respectively. For example:

 
pip install package_name>=1.0.4

This will install the latest version of the package that is greater than or equal to 1.0.4.

Finally, you can use the ~= operator to specify a minimum and maximum version number. For example:

 
pip install package_name~=1.0.4

This will install the latest version of the package that is compatible with version 1.0.4 (i.e., the package should have the same major and minor version numbers as 1.0.4, but the patch number can be different).

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →