How to install Pip on CentOS 8

In this tutorial, we will use the yum package manager to install Python pip on CentOS 8 and introduce the basics of how to install and manage Python packages using pip. In the CentOS 8 repository AppStream, there is both a pip version of Python 2 and a Python 3 interpreter. The pip command now runs with the pip2 or pip3 commands, respectively.

What is picture-in-picture?

pip is Python’s standard package (module) manager. It allows you to install and manage other packages that are not part of the Python standard library. Modules are Python code libraries that you can include and use in your projects. Starting with version 3.4 of Python 3 and version 2.7.9 of Python 2, pip has been included in the Python installer, and it is used by many Python projects, making it an essential tool for every Python programmer.

Mounting point

In CentOS 8, you can use dnf or yum commands to install packages. We can install the pip2 or pip3 packages depending on the version of python used, or we can install both packages without any problems.

Install python2-pip

First, we update the system:

$ sudo yum update

We will install both the python2-pip and python3-pip packages. First, we install python2-pip:

$ sudo yum -y install python2-pip
Last metadata expiration check: 2:12:46 ago on Tue 01 Oct 2019 01:19:15 PM UTC.
Dependencies resolved.
===============================================================================
 Package           Arch   Version                              Repository
                                                                          Size
===============================================================================
Installing:
 python2-pip       noarch 9.0.3-13.module_el8.0.0+32+017b2cba  AppStream 2.0 M
Installing dependencies:
 python2           x86_64 2.7.15-22.module_el8.0.0+32+017b2cba AppStream 107 k
 python2-libs      x86_64 2.7.15-22.module_el8.0.0+32+017b2cba AppStream 6.0 M
 python2-setuptools
                   noarch 39.0.1-11.module_el8.0.0+32+017b2cba AppStream 643 k
Enabling module streams:
 python27                 2.7                                                 

Transaction Summary
===============================================================================
Install  4 Packages

Total download size: 8.7 M
Installed size: 36 M
Downloading Packages:
(1/4): python2-2.7.15-22.module_el8.0.0+32+017  70 kB/s | 107 kB     00:01    
(2/4): python2-setuptools-39.0.1-11.module_el8 689 kB/s | 643 kB     00:00    
(3/4): python2-pip-9.0.3-13.module_el8.0.0+32+ 777 kB/s | 2.0 MB     00:02    
(4/4): python2-libs-2.7.15-22.module_el8.0.0+3 1.4 MB/s | 6.0 MB     00:04    
-------------------------------------------------------------------------------
Total                                          2.0 MB/s | 8.7 MB     00:04     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                       1/1 
  Installing       : python2-libs-2.7.15-22.module_el8.0.0+32+017b2cba.x   1/4 
  Installing       : python2-pip-9.0.3-13.module_el8.0.0+32+017b2cba.noa   2/4 
  Installing       : python2-setuptools-39.0.1-11.module_el8.0.0+32+017b   3/4 
  Installing       : python2-2.7.15-22.module_el8.0.0+32+017b2cba.x86_64   4/4 
  Running scriptlet: python2-2.7.15-22.module_el8.0.0+32+017b2cba.x86_64   4/4 
  Verifying        : python2-2.7.15-22.module_el8.0.0+32+017b2cba.x86_64   1/4 
  Verifying        : python2-libs-2.7.15-22.module_el8.0.0+32+017b2cba.x   2/4 
  Verifying        : python2-pip-9.0.3-13.module_el8.0.0+32+017b2cba.noa   3/4 
  Verifying        : python2-setuptools-39.0.1-11.module_el8.0.0+32+017b   4/4 

Installed:
  python2-pip-9.0.3-13.module_el8.0.0+32+017b2cba.noarch                       
  python2-2.7.15-22.module_el8.0.0+32+017b2cba.x86_64                          
  python2-libs-2.7.15-22.module_el8.0.0+32+017b2cba.x86_64                     
  python2-setuptools-39.0.1-11.module_el8.0.0+32+017b2cba.noarch               

Complete!

Install python3-pip

We install the python3-pip package in the same way:

$ sudo yum -y install python3-pip
CentOS-8 - AppStream                           3.3 kB/s | 4.3 kB     00:01    
CentOS-8 - Base                                1.7 kB/s | 3.8 kB     00:02    
CentOS-8 - Extras                              1.4 kB/s | 1.5 kB     00:01    
Docker CE Stable - x86_64                      3.1 kB/s | 3.5 kB     00:01    
Extra Packages for Enterprise Linux 8 - x86_64  17 kB/s |  32 kB     00:01    
Extra Packages for Enterprise Linux 8 - x86_64 464 kB/s | 1.8 MB     00:04    
Dependencies resolved.
===============================================================================
 Package            Arch   Version                             Repository
                                                                          Size
===============================================================================
Installing:
 python3-pip        noarch 9.0.3-13.el8                        AppStream  18 k
Installing dependencies:
 python36           x86_64 3.6.8-2.module_el8.0.0+33+0a10c0e1  AppStream  19 k
 python3-setuptools noarch 39.2.0-4.el8                        BaseOS    162 k
Enabling module streams:
 python36                  3.6                                                

Transaction Summary
===============================================================================
Install  3 Packages

Total download size: 200 k
Installed size: 466 k
Downloading Packages:
(1/3): python3-pip-9.0.3-13.el8.noarch.rpm      15 kB/s |  18 kB     00:01    
(2/3): python36-3.6.8-2.module_el8.0.0+33+0a10  14 kB/s |  19 kB     00:01    
(3/3): python3-setuptools-39.2.0-4.el8.noarch.  97 kB/s | 162 kB     00:01    
-------------------------------------------------------------------------------
Total                                           70 kB/s | 200 kB     00:02     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                       1/1 
  Installing       : python3-setuptools-39.2.0-4.el8.noarch                1/3 
  Installing       : python36-3.6.8-2.module_el8.0.0+33+0a10c0e1.x86_64    2/3 
  Running scriptlet: python36-3.6.8-2.module_el8.0.0+33+0a10c0e1.x86_64    2/3 
  Installing       : python3-pip-9.0.3-13.el8.noarch                       3/3 
  Running scriptlet: python3-pip-9.0.3-13.el8.noarch                       3/3 
  Verifying        : python3-pip-9.0.3-13.el8.noarch                       1/3 
  Verifying        : python36-3.6.8-2.module_el8.0.0+33+0a10c0e1.x86_64    2/3 
  Verifying        : python3-setuptools-39.2.0-4.el8.noarch                3/3 

Installed:
  python3-pip-9.0.3-13.el8.noarch                                              
  python36-3.6.8-2.module_el8.0.0+33+0a10c0e1.x86_64                           
  python3-setuptools-39.2.0-4.el8.noarch                                       

Complete!

Next, we should verify that the package installation went smoothly.

Confirm the installation by querying the version number

We will query the version information about python2-pip and python3-pip using the following command:

$ pip2 -V
pip 9.0.3 from /usr/lib/python2.7/site-packages (python 2.7)

For python3-pip, we enter:

$ pip3 -V
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)

Search for python packages

Suppose we want to install some modules using pip, but we don’t know the exact module name. We can use keywords to search for available packages.

$ pip2 search docker

Either

$ pip3 search docker
docker (4.0.2)                      - A Python library for the Docker Engine
                                      API.
docker-utils (0.1.4)                - Utilities for Docker
Fifty-Docker (1.1)                  - Docker utilities.
monit-docker (0.0.32)               - monit-docker
docker-deployer (0.1.0)             - A Fabric framework for Docker
                                      deployment based on Docker-Compose.
docker-pid (0.0.3)                  - docker-pid: Listing process IDs in
                                      docker containers.
docker-fabric (0.5.0)               - Build Docker images, and run Docker
                                      containers in Fabric.
morgaroth-docker (0.0.1)            - Morgaroths Docker Client
docker-api (0.1.3)                  - Docker API Client
docker-wrapper (2.1.2)              - Docker Wrapper for Python
docker-registry (0.9.1)             - Registry server for Docker
docker-py (1.10.6)                  - Python client for Docker.
docker-cloud (1.0.9)                - CLI for Docker Cloud
docker-dev (1.0b2)                  - Development tools for Docker
pysecrets-docker (1.0.0)            - Docker secrets to ENV
docker-master (0.0.2)               - An alternative to docker-compose
bonobo-docker (0.6.0)               - Docker extension for Bonobo
colomoto-docker (7.2)               - Helper script to run docker image
                                      colomoto/colomoto-docker
docker-parse (0.5.6)                - Parse docker-run options from a running
                                      Docker container

.....

The list continues, but in the next example, we will choose to install the docker-fabric module.

Install modules (packages) using PIP

We can install the docker-fiber package using a simple pip command:

$ pip3 install docker-fabric
Collecting docker-fabric
  Downloading https://files.pythonhosted.org/packages/1d/66/2c75e141373dca58ec20ccdbb2b2204a07e02f692c7fc42c83fe98e71bfd/docker-fabric-0.5.0.tar.gz
Requirement already satisfied: six in /usr/lib/python3.6/site-packages (from docker-fabric)
Collecting Fabric>=1.8.0 (from docker-fabric)
  Downloading https://files.pythonhosted.org/packages/d7/cb/47feeb00dae857f0fbd1153a61e902e54ed77ccdc578b371a514a3959a19/fabric-2.5.0-py2.py3-none-any.whl (51kB)
    100% |████████████████████████████████| 61kB 1.3MB/s 
Collecting docker-py>=1.9.0 (from docker-fabric)
  Downloading https://files.pythonhosted.org/packages/23/c7/1fd6d4d620809fe2f323869d719e2dd0086c939b67021303a9ec40f5a05b/docker_py-1.10.6-py2.py3-none-any.whl (50kB)
    100% |████████████████████████████████| 51kB 4.8MB/s 
Collecting docker-map>=0.8.0b2 (from docker-fabric)
  Downloading https://files.pythonhosted.org/packages/c8/31/b23be95ca29113b0af3fc3c931de5f471f3a7e07af0d4ce29d47445dcc07/docker-map-1.0.0.tar.gz (109kB)
    100% |████████████████████████████████| 112kB 2.5MB/s 
Collecting paramiko>=2.4 (from Fabric>=1.8.0->docker-fabric)
  Downloading https://files.pythonhosted.org/packages/4b/80/74dace9e48b0ef923633dfb5e48798f58a168e4734bca8ecfaf839ba051a/paramiko-2.6.0-py2.py3-none-any.whl (199kB)

....

  Running setup.py install for docker-map ... done
  Running setup.py install for docker-fabric ... done
Successfully installed Fabric-2.5.0 bcrypt-3.1.7 certifi-2019.9.11 chardet-3.0.4 cryptography-2.7 docker-fabric-0.5.0 docker-map-1.0.0 docker-py-1.10.6 docker-pycreds-0.4.0 invoke-1.3.0 paramiko-2.6.0 pynacl-1.3.0 requests-2.22.0 urllib3-1.25.6 websocket-client-0.56.0

List installed packages

To list the installed packages, we use the following command:

$ pip3 list

bcrypt (3.1.7)
certifi (2019.9.11)
cffi (1.11.5)
chardet (3.0.4)
configobj (5.0.6)
cryptography (2.7)
decorator (4.2.1)
docker-fabric (0.5.0)
docker-map (1.0.0)
docker-py (1.10.6)
docker-pycreds (0.4.0)
fabric (2.5.0)
gpg (1.10.0)
idna (2.5)

.....

To list outdated packages, enter:

$ pip2 list --outdated
pip (9.0.3) - Latest: 19.2.3 [wheel]
setuptools (39.0.1) - Latest: 41.2.0 [wheel]

Module removal using PIP (packaging)

The only thing left in this tutorial is how to delete the pip package. It’s simple, we enter:

$ pip3 uninstall docker-fabric
Uninstalling docker-fabric-0.5.0:
  /usr/local/lib/python3.6/site-packages/docker_fabric-0.5.0-py3.6.egg-info
  /usr/local/lib/python3.6/site-packages/dockerfabric/__init__.py
  /usr/local/lib/python3.6/site-packages/dockerfabric/__pycache__/__init__.cpython-36.pyc
  /usr/local/lib/python3.6/site-packages/dockerfabric/__pycache__/actions.cpython-36.pyc
  /usr/local/lib/python3.6/site-packages/dockerfabric/__pycache__/api.cpython-36.pyc
  /usr/local/lib/python3.6/site-packages/dockerfabric/__pycache__/apiclient.cpython-36.pyc

.....

  /usr/local/lib/python3.6/site-packages/dockerfabric/utils/output.py
  /usr/local/lib/python3.6/site-packages/dockerfabric/utils/users.py
  /usr/local/lib/python3.6/site-packages/dockerfabric/yaml.py
Proceed (y/n)? y

You will see a list of files to be deleted. When we continue to type y, the package will be deleted.

Proceed (y/n)? y
  Successfully uninstalled docker-fabric-0.5.0

in conclusion

You have successfully installed pip on a CentOS 8 system and learned how to easily install and uninstall Python modules using pip. For more information, you can check out the pip user guide. If you have any questions or feedback, please leave a comment below.

Also read:

  • How to set up a Python virtual environment on Ubuntu 18.04
Sidebar