
In this tutorial, we will install Python pip on CentOS 8 using the yum package manager and cover the basics of how to install and manage Python packages with pip. In the CentOS 8 repository AppStream, there are both pip versions for Python 2 as well as Python 3 interpreter. pip command is now run with pip2 or pip3 command respectively.
What is PIP?
pip is the standard package (module) manager for Python. It allows you to install and manage additional packages that are not part of the Python standard library. Modules are Python code libraries you can include and use in your projects. pip has been included with the Python installer since versions 3.4 for Python 3 and 2.7.9 for Python 2, and it’s used by many Python projects, which makes it an essential tool for every Python programmer.
Installing pip
In CentOS 8 you can install packages either with dnf or yum command. We can install pip2 or pip3 package depending on what python version we use, or we could also install both packages as well, without any problem.
Installing python2-pip
First, we update the system:
$ sudo yum update
We will install both 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!
Installing python3-pip
We install python3-pip package 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 the package installation went well.
Confirming the installation by querying the version number
We will query version info on python2-pip and python3-pip with the following commands:
$ pip2 -V
pip 9.0.3 from /usr/lib/python2.7/site-packages (python 2.7)
For python3-pip we type:
$ pip3 -V
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)
Searching for python packages
Let say we want to install some module with pip but we don't know the exact module name. We can search for the available packages using a keyword.
$ pip2 search docker
or
$ 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 goes on, but we'll choose to install the docker-fabric module in the next example.
Installing 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 installed packages we use this 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, we type:
$ pip2 list --outdated
pip (9.0.3) - Latest: 19.2.3 [wheel]
setuptools (39.0.1) - Latest: 41.2.0 [wheel]
Removing modules (packages) using PIP
The only thing left to see in this tutorial is how to remove the pip package. It is fairly simple, we type:
$ 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 be presented with the file list about to be removed. When we proceed by typing y, the package will be removed.
Proceed (y/n)? y
Successfully uninstalled docker-fabric-0.5.0
Conclusion
You have successfully installed pip on your CentOS 8 system and you learned how to easily install and uninstall Python modules with pip. For more information, you can check the pip user guide. If you have any questions or feedback, feel free to comment below.