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 manage Python packages with pip.
What is pip?
Pip is a package management system that allows you to install, remove, and otherwise manage software packages written in Python. It can be used to install packages from the Python Package Index (PyPI) and other indexes.
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.
First, we update the system:
# sudo yum update or # sudo dnf update
First, we install python2-pip:
# sudo yum -y install python2-pip or # sudo dnf -y install python2-pip
We install python3-pip package the same way:
# sudo yum -y install python3-pip or # sudo dnf -y install python3-pip
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)
How to Use Pip
We will go through some basics of Pip commands.
pip2in your commands if you are using Python 2.
Install Packages Using Pip
To install a package using Pip, you can use the below command.
# pip3 install PACKAGE_NAME
For example, to install the latest version of IPython package, a powerful interactive Python shell, use the below command.
# pip3 install IPython
The above command will download all the necessary files and install the specified package.
To install a specific version of the package (Example 6.0), you can use the below command.
# pip3 install IPython==6.0
List Installed Pip Packages
To list the installed Python packages, use the below command.
# pip3 list
................. gpg (1.10.0) idna (2.5) iniparse (0.4) ipython (7.13.0) ipython-genutils (0.2.0) jedi (0.16.0) netifaces (0.10.6) parso (0.6.2) ............
Upgrade Package Using Pip
To upgrade a package to the latest version, use the below command.
# pip3 install --upgrade IPython
Remove Package Using Pip
If you want to remove a package installed via pip, you can use the below command.
# pip3 uninstall IPython
Search Packages using Pip
Pip’s search functionality lets you search for packages (name). This command will get the packages list from the PyPI (Python Package Index).
# pip3 search google
google (2.0.2) - Python bindings to the Google search engine. oauthkit-google (0.1.2) - OAuthKit for Google bits-google (1.8.6) - BITS Google google-gax (0.16.0) - Google API Extensions google-finance (0.1.0) - Google Finance API google-oauth (1.0.1) - OAuth2 for Google APIs google-auth (1.6.3) - Google Authentication Library ...........................
We’ve shown you how to install pip on CentOS 8 and how to easily install and uninstall Python modules with pip.
For more information about pip, check the pip user guide . If you have any questions or feedback, feel free to comment below.