Install Specific Python Package Version with Pip

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 the Python Package

The lastest 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 Latest Version of the 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.

$ pip3 install numpy

Install Specific Version of The 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 the Pip.
  • VERSION is the previous or older version of the specified PACKAGE which will be installed.

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 specific project. The package names are specified line by line in the requirements.txt and you can also specify 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

Leave a Comment