CentOS

Install Python PIP on CentOS7

Python PIP is a package manager for Python, just like Yum is a package manager for CentOS 7 and RHEL 7.

In this article, I will show you how to install Python 2 PIP and Python 3 PIP on CentOS 7. Let’s get started.

Pre-requisites:

First update the package repository cache of yum package manager with the following command:

$ sudo yum makecache

The yum package repository cache should be updated.

Python PIP is not available in the official package repository of CentOS 7. But it is available in the EPEL package repository. Before you can install Python PIP on CentOS 7, you must add EPEL repository to your CentOS 7.

To add EPEL package repository on CentOS 7, run the following command:

$ sudo yum install epel-release

Press ‘y’ and then press <Enter> to continue.

EPEL package repository should be added.

Now update the package repository cache of your CentOS 7 again with the following command:

$ sudo yum makecache

The package repository cache should be updated.

Now you’re ready to install Python PIP.

PIP is available for Python 2 and Python 3 in the EPEL repository. In this article, I will show you how to install Python 2 PIP and Python 3 PIP.

Installing Python 2 PIP:

In this section, I will show you how to install Python 2 PIP.

Run the following command to install Python 2 PIP:

$ sudo yum install python-pip

Press ‘y’ and then press <Enter> to continue.

Press ‘y’ and then press <Enter> to accept the GPG key.

Python 2 PIP should be installed.

You can run the following command to check whether Python 2 PIP is working.

$ pip -V

As you can see the version of PIP installed is PIP 8.1.2. By the time you read this, the version may change but don’t worry about it. It should work the same way.

Installing Python 3 PIP:

In this section I am going to show you how to install Python 3 PIP.

At the time of this writing, on EPEL repository of CentOS 7, Python 3.4 is available. By the time you read this article, the package version may change. If the package version changes, so will the package name. So I am not going to install any specific version of Python 3 PIP. I will show you how to search for it and install what is available when you read this article.

You can run the following command to search for a Python 3 PIP package:

$ sudo yum search pip | grep python3

As you can see from the marked section of the screenshot below, the package name of Python 3 PIP is python34-pip.

Now you can install Python 3 PIP with the following command:

$ sudo yum install python34-pip

Now press ‘y’ and then press <Enter> to continue.

Python 3 PIP should be installed.

Now you can check whether Python 3 PIP is working with the following command:

$ pip3 -V

As you can see from the screenshot below, the version of Python 3 PIP installed on my CentOS 7 machine is 8.1.2.

Searching for a Python Package using PIP:

You can search for a python package using PIP. Let’s say you want to search Python API for ‘twitter’. You can do so by running the following command:

Python 2 PIP:

$ pip search twitter

Python 2 PIP search result for twitter:

Python 3 PIP:

$ pip3 search twitter

Python 3 PIP search result for twitter:

Installing a Python Package using PIP:

You can install a Python package using PIP. Let’s say you want to install Flask – a micro web framework for Python which is very lightweight.

You can do so with the following command:

Python 2 PIP:

$ sudo pip install flask

As you can see, Flask is being downloaded.

Flask should be installed as you can see from the screenshot below:

Python 3 PIP:

For Python 3, the above command should be:

$ sudo pip3 install flask

Removing a Package using PIP:

To remove a package using PIP, run the following command:

Python 2 PIP:

$ sudo pip uninstall PACKAGE_NAME

Pres ‘y’ and then press <Enter> to continue.

It should be removed.

Python 3 PIP:

$ sudo pip3 uninstall PACKAGE_NAME

That’s how you install Python PIP on CentOS 7. Thanks for reading this article, and for more information on Python check out the Python programming books below:

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.