Python provides the pip package manager in order to install packages. By default, the pip package manager will install the latest version of the pip or Python package. But in some cases, you may need to install an older or specific version of the Python package by using the pip. This is generally required to meet dependencies. The pip install is used to install a specific or older version of the given Python package.
Show Latest Version of A Python Package
The latest version of the specific package can be displayed by using the pip3 show
command and the package name. In the following example, we will list the latest version of the numpy package.
$ pip3 show numpy

From the Version line we can see that the current or latest numpy package version is 1.19.1.
Install The Latest Version of A Python Package
If we want to install the latest version of the package just provide the package name to the pip3 install
command. In the following example, we will install the latest version of the numpy package. Unless explicitly specified the pip and pip3 commands install the latest version of the specified Python package.
$ pip3 install numpy
Install Specific Version of a Python Package
Even by default, the pip install command installs the latest version of the given Python package you can also install previous versions of the Python packages. In order to install the previous version or a specific version of the Python package, you should specify the package version by using the == equal signs. In the following example, we will install the specific version of 1.18 for the numpy package.
$ pip3 install numpy=1.18
The syntax to install spefici version of the Python package is like below.
pip install PACKAGE==VERSION
- PACKAGE is the official package name which is provided by Pip.
- VERSION is the previous or older version of the specified PACKAGE that will be installed. The VERSION consists of major and minor version numbers wherein 1.18 the 1 is the major version number and 18 is the minor version number.
If the version number provides multiple minor version numbers all of them can be specified. For example, the following pip command installs the abc version 1.20.3
$ pip3 install abc=1.20.3
Install Specific Version of A Python Package Which Is Allready Install
If a package is already installed with a version that is different from the version we want to install this may create problems. The simplest solution is uninstalling or removing the previously installed version of the Python package. The -Iv
option can be used to remove or delete all previously installed versions of the specified Python package. In the following example, we install numpy package version 1.18 by uninstalling and removing existing numpy packages with different versions.
$ pip3 install -IV numpy=1.18
Install Specific Version of Python Package from requirements.txt
The requirements.txt is used to store multiple packages which will be installed with a single command. This is generally used to provide the requirements for a specific project. The package names are specified line by line in the requirements.txt and you can also specify a specific version of the Python package. The requirements.txt file content will be like below.
numpy==1.18
django==1.7
WebTip==1.0
And this requirements.txt file contents can be installed with the following command. We will provide the requirements.txt file with the -r parameter like below.
$ pip3 install -r requirements.txt