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).

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github