pip centos8

Pip is a package management system that allows you to install, remove and manage packages written in Python. It can be used to install packages from the Python Package Index (PyPI) and other indexes.

In this tutorial, we will explain how to install pip for Python 2 and 3 on CentOS 8, and cover the basics of how to use pip to manage Python packages.

Installing pip on CentOS 8

As you know, there are two versions of Python under active development, Python 2 and Python 3. By default, RHEL/CentOS 8 does not have a full system version of the python command to avoid locking users into a specific version of Python. Instead, it gives users the option to install, configure, and run specific versions of Python.

When installing python modules globally, you should prefer to use dnf or yum to install python modules from the distribution repository, as they have been tested to work properly on CentOS 8. Use pip to install python modules globally only if there are no rpm packages available to install python modules.

Python 2 packages are named with the prefix “python2”, while Python 3 modules are prefixed with “python3”. For example, to install the paramiko module for Python 3, you would run:

1
sudo dnf install python3-paramiko

Installing pip for Python 3 (pip3)

To install pip for Python 3 on CentOS 8, run the following command in a terminal as the root or sudo user.

1
sudo dnf install python3

This command will install Python 3.6 and pip. to run Python 3, you need to explicitly type python3 and to run pip type pip3.

Verify that pip is correctly installed by running the following command, which will display the pip version.

1
pip3 --version

The version number may vary, but it should look like this.

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

To be able to install and build Python modules via pip, you need to install the development tools.

1
2
sudo yum install python3-devel
sudo yum groupinstall 'development tools'

Installing pip for Python 2 (pip2)

To install Python 2 and pip, enter the following command.

1
sudo dnf install python2

Verify the installation by typing the following.

1
pip2 --version

The output should look like the following.

1
Python 2.7.15

To execute Python 2, type python2 and then run the pip type pip2.

Install the development tools.

1
2
sudo yum install python2-devel
sudo yum groupinstall 'development tools'

Managing Python packages with pip

In general, you should only use pip in virtual environments. Python Virtual Environments virtual environments allow you to install Python modules in isolated locations in a given project, without having to install them globally. This way, you don’t have to worry about affecting other Python projects.

In this section, we will cover some basic pip commands.

To install python modules using pip, run pip install and enter the package name. For example, to install a package named twisted, you would run the following command.

1
pip install twisted

twisted is an asynchronous networking framework written in Python.

To install a specific version of the package, use the following format.

1
pip install twisted==19.10.0

To uninstall a package, use pip uninstall followed by the package name.

1
pip uninstall package_name

To search for packages from PyPI.

1
pip search "package_name"

List the installed packages.

1
pip list

List outdated packages.

1
pip list --outdated

To upgrade an installed package to the latest version, use the following command.

1
pip3 install --upgrade package_name