Installing specific package version with pip

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

pip install SomePackage==1.0.4

This will install version 1.0.4 of the SomePackage package. You can also specify a version range using comparison operators like >, >=, <, and <=. For example:

pip install SomePackage>=2.0.0,<3.0.0

This will install any version of SomePackage that is greater than or equal to 2.0.0 and less than 3.0.0.

Watch a course Python - The Practical Guide

You can also use the --upgrade flag to upgrade to the specified version if you have a previous version of the package installed:

pip install SomePackage==1.0.4 --upgrade

Keep in mind that specifying a version number or version range is only necessary if you want to install a specific version of a package. If you omit the version number, pip will install the latest version of the package that is available.