How To Install Specific Version Of Python Package with Pip? – POFTUT

How To Install Specific Version Of Python Package with Pip?


Pip is the most popular tool and the command used to install 3rd party packages into Python. pip can be used for both PYython2 and Python3. In this tutorial, we will learn how to install a specific version of a Python package with the pip command.

Search Package

Before installing a specific version of the Python package we can search the package for its complete name and version information. We will use search command in this example.

$ pip search django
Search Package
Search Package

Show Package Information and Version

We can show the Python package information like name, version, etc. The inversion information is important because we will install a specific version or downgrade the Python package.

$ pip show django
Show Package Information and Version
Show Package Information and Version

Install Specific Package Version with pip Command

We will install a specific version of the Django Python package with pip. We will specify the version we want to install with the equal sign. In this example, we will install the Django version 2.2.1 which is not recent. We will use a double equation sign to specify the version. We will also use the --user option in order to prevent other system users package downgrade. This will only affect the current user.

$ pip3 install --user django==2.2.1
Install Specific Package Version with pip Command
Install Specific Package Version with pip Command

From the screenshot, we see that the currently installed recent Django version is uninstalled automatically.

Install Package Version Which Is In Specified Range with pip Command

In the previous example, we have installed a specific django version. But we can also specify the version range with the >= or <=. This will select the latest version which complies with the given expression and install it.

$ pip install django < 2
Install Package Version Which Is In Specified Range with pip Command
Install Package Version Which Is In Specified Range with pip Command

Force Installation of  Specific Package Version with pip Command

If there are some minor problems related to the installation, dependency, etc. We can force the installation with the --force-reinstall option.

$ pip3 install --force-reinstall --user django==2.2.1

Remove Specific Package Version with pip Command

We can also remove the specific package version with the pip command. There is a different alternative. As only a single version can be installed at the same time different version installation will uninstall currently installed version.

$ pip uninstall django

$ pip2 uninstall django

$ pip2 uninstall django
Remove Specific Package Version with pip Command
Remove Specific Package Version with pip Command

LEARN MORE  How To Install Numpy For Linux?

Leave a Comment