Use Pip to Install Python Version

Rana Hasnain Khan May 13, 2022
Use Pip to Install Python Version

We will introduce how we can install packages of specific versions using pip in Python. We will get a concise introduction on versions of packages and when and which version we should install.

Use Pip to Install a Specific Python Version

Usually, installing the latest version of the required program is recommended, but there are cases where a specific version only fulfills our needs. There may be many motives that we may wish to install an older version of the package.

If we have a version of Python that is not compatible with the latest version of the package available, or it is not harmonious with other packages that we have already installed or with the python code that we have.

We can install an older package version if we have other package managers such as package manager conda (anaconda python distribution). The basic pip syntax that will help us install our desired version of a python package is as follows:

# python
pip install <Package Name>==<Version Of Package>

From this syntax, we can choose the package and desired version. Let us have an example; suppose we require an older version of Pandas; we can install it by opening Windows Command Prompt or any terminal emulator in Linux.

We can run the following command as shown below.

# python
pip install tensorflow==1.15

We can also install our desired version using conda.

Before installation, we should have a virtual environment. So to meet this condition, we have to install the virtualenv package.

Let us install the virtualenv using the pip. If we don’t specify any version of the package we want to install, Python will download the latest version, as shown below.

# python
pip install virtualenv

After that, we have to create our environment, and then we can initiate it.

# python
virtualenv myProjects myProject/bin/activate

This completed our first step, and now we can move towards the next and our main step, which is to install an older version of the package. As we have used pip in the first step to install the virtualenv, we will use pip once more.

The general syntax which is mentioned before will help us in installation. Now, we can install the desired version by mentioning the version of the package that we want to install, as shown below.

# python
pip install tensorflow==1.15

By following the above steps, we can easily install our desired version. But if we want to install multiple Python packages at once, these steps may not be of any use.

To install multiple packages, we can generate a .txt file. Here is an example to show you how we can create a text file.


One condition evident from this example is that we have to stack each package in a text file on one line. We can easily install all the packages with their specific version using the following command below.

# python
pip install -r myproject/requirements.txt

Older versions are not recommended because of a reason. There are many issues related to the package dependencies when installing older versions.

One main issue that appears is that it can destroy our application or may disrupt our workflow. To resolve this issue, here are some solutions that might help us.

We can mimic our data analysis using Binder, Jupyter Notebooks, and Python.

On the other hand, this solution might not work if we develop applications. This concludes the learning of how we can install specific versions of Python packages.

Rana Hasnain Khan avatar Rana Hasnain Khan avatar

Rana is a computer science graduate passionate about helping people to build and diagnose scalable web application problems and problems developers face across the full-stack.


Related Article - Python Version