How To Install Specific Package Version with Pip Command?

The pip is a command and tool used to install, update and remove 3rd part packages for Python. The pip is generally used to install and update packages but there are different use cases. By default, the pip command installs the latest version of the specified package. But Python is a very dynamic language where its environment is dynamic too and the package versions change regularly. But in order to run a python script or code a specific and old package may be required for compatibility. In this tutorial, we will learn how to install a specific Python package or module with the pip command.

Install Specific Package Version

By default, the pip command uses the install option and the package name in order to install the latest version. But if we have to install the previous version which is a specific package version the == sign can be used to specify the version we want to install. For example, in order to install the MySQL_python package version, the 1.2.1 following command can be used.

pip install MySQL_python==1.2.1

Remove Other Versions and Then Install Specific Package Version

If you installed a specific version but when try to use the installed package you may get an error. There are different reasons but the most common reason is the versions can collide. We can remove other versions with the -Iv option.

pip install -Iv MySQL_python==1.2.1

Force Installation of Specific Package Version

If there are some problems like errors, collusion, or already installed we can force the installation of the specific package with the –force-install option like below.

pip install --force-install MySQL_python==1.2.1

Install Specific Version Range

In order to install specific Python package version a range can be specified. The comparison operators like >= or <= can be used like below.

pip install MySQL_python>=1.2.1

Leave a Comment