In this tutorial, we will learn how to install pip3 / pip2 on Rocky/ RHEL/Ubuntu/Debian/CentOS Linux Operating System. After installation method, you will get some pip command examples. It will help you to kickstart on pip command.
In this post we have covered both pip3 and pip2 installation method.
We have been maintaining this post since pip 2.x version. Please find the right Operating System where you want to install pip by using Index as given below.
Introduction: pip (Python Package Installer)
PIP is the alternate python package installer. pip is famous for easily managing the python based packages. As well as, with the help of pip you can also install the package of particular version. Most importantly pip has a feature to manage full lists of packages and corresponding version numbers, possible through a “requirements” file.
Very important to note that when we want to install particular python based package for example python 3 based package then for installing these package we need specific pip version. In such case, the pip version starts with same number which python has.
In other words, Python 3.x based package need pip3.x, Python 2.x based package need pip 2.x . We hope upto this you are clear.
It performs the same basic job as easy_install
tool do but with some extra features. It can work with version control repositories (currently only Git, Mercurial, and Bazaar repositories), logs output extensively, and prevents partial installs by downloading all requirements before starting installation.
It has some disadvantages when compared to easy_install
. It does not use egg files, although it does preserve egg metadata. Some setuptools features are not yet supported, and some custom setup.py features won´t work.
How To Determine Which pip Version Should We Install ?
It is very simple rule to follow, When you have Python version 3.x installed then you should use the pip 3.x version.
Similarly, if you have Python 2.x version then use pip 2.x version.
Basically pip is package manager for python so as per the Python version you must have same version of pip.
Steps To Install pip on CentOS / RHEL / Rocky Linux
In this section we will learn how to install the pip. I would like to recommend here to read the post completely because through this you know about some history of pip installation method.
Install pip In RHEL 9.x And Rocky Linux 9.x
In RHEL 9.x and Rocky Linux 9.x , the Python 3.x is shipped by default in the Operating System. Hence, the pip3 can be installed directly. There is no change in the command.
sudo dnf install -y python3-pip
Note: In CentOS Stream 9, you can install the pip with the same command but CentOS Stream is not meant for Production Server hence we are not encouraging the CentOS in our post.
Install pip In RHEL 8.x And CentOS 8.x
In CentOS 8 and RHEL 8, it is user choice to install the python version. As we know the Python 2.x has end of life in 2020.
Basically we need pip for managing the python packages. In CentOS 8/RHEL when you install the Python 3.x by dnf
command , it also install pip 3 as a dependency.
So this command is for installing Python 3.x and pip3 as well.
sudo dnf install -y python3
If you do not have pip 3.x in your CentOS 8 / RHEL 8 system then only use the given below command.
sudo dnf install -y python3-pip
After installing pip 3 on CentOS 8 / RHEL 8, use pip3
command to manage the python packages. To check the help for pip3 command, use the given below command.
pip3 --help
Install pip in RHEL 7.x and CentOS 7.x (x86_64)
For installing pip in RHEL 7.x and CentOS 7.x . We have to take two action
- Install EPEL Repo as per the supporting Operating System Architecture.
- Install pip With Yum Command
Install EPEL Repo In RHEL 7.x and CentOS 7.x (x86_64)
First install the EPEL repo as per your Operating system version and architecture.
For detail study, you can read our previous post on EPEL.
We have already written post on “Install EPEL repo on CentOS 7 / RHEL 7” with more details. Below given command will install EPEL repo on CentOS 7 / RHEL 7.
yum install epel-release
Install pip with yum command in RHEL 7.x And CentOS 7.x
After installing the EPEL repo . Now install the pip . This will fetch the pip package from the EPEL yum repository.
yum install -y python-pip
Install pip In RHEL 6.x And CentOS 6.x
By using arch
command first check if your Operating System has x86_64(64 bit) or i386(32 bit) arch. Then accordingly we will install the EPEL package.
Install EPEL Repo Supporting x86_64 Package in RHEL 6.x And CentOS 6.x
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Install EPEL Repo Supporting i386 Package RHEL 6.x And CentOS 6.x
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
Install pip With Yum Command In RHEL 6.x And CentOS 6.x
Now install pip with yum command
yum install -y python-pip
The pip rpm will be installed. You can confirm it by using following command.
See below given reference :
[root@localhost ~]# which pip /usr/bin/pip [root@localhost ~]# [root@localhost ~]# rpm -qa|grep pip python-pip-1.3.1-4.el6.noarch [root@localhost ~]#
Steps To Install pip on Debian / Ubuntu
In this section, we will learn how to install pip in Debian and Ubuntu. This method is applicable to all the Debian based Operating System.
Install pip in Ubuntu 22.04 LTS
When you install the Ubuntu 22.04 LTS, you will get the python 3 version by default . So we will go straight for installing the pip on Ubuntu 22.04 LTS Operating System.
You will notice that because we have python 3 version in Ubuntu 22.04 LTS, the pip package name is also python3-pip.
sudo apt-get -y update sudo apt install python3-pip
After installing the pip3 you can directly start using the command. To know more about the pip available options, use the command
pip --help
Install pip in Ubuntu 20.04 LTS
As we know, the python 2.x is on sunset. In Ubuntu 20.04 LTS, it is shipped with Python 3.6. Hence, we will install the pip3 version.
Install the pip 3 by using apt-get command
sudo apt-get -y update sudo apt install python3-pip
To manage the python 3.x packages, use the pip3
command.
You check its help.
pip3 --help
Install pip on Ubuntu 16.04 LTS and 18.04 LTS
In Ubuntu 16.04 LTS and 18.04 LTS install the pip by using apt command. In both the operating system, method is same.
sudo apt update sudo apt install python-pip
How To Confirm pip Package Installation In Debian / Ubuntu
To confirm the package installation.Given below is the reference from my system
sharad@ubuntu:~$ sudo dpkg -l|grep pip [sudo] password for sharad: ii libpipeline1:amd64 1.3.0-1 amd64 pipeline manipulation library ii python-pip 1.5.4-1 all alternative Python package installer sharad@ubuntu:~$ sharad@ubuntu:~$ which pip /usr/bin/pip sharad@ubuntu:~$
How to use pip command
After installing python-pip package, the pip command will be available on system.
There are multiple options available with pip command.
Most commonly used are install and uninstall of python package.
Installing Package With pip Command
Use given below syntax to install the package.
sudo pip install python-package-name
Let’s see one example. Here, we will install the boto3 module.
[root@localhost ~]# pip install boto3 Collecting boto3 Downloading boto3-1.26.96-py3-none-any.whl (135 kB) |████████████████████████████████| 135 kB 2.2 MB/s Collecting botocore<1.30.0,>=1.29.96 Downloading botocore-1.29.96-py3-none-any.whl (10.5 MB) |████████████████████████████████| 10.5 MB 7.8 MB/s Collecting jmespath<2.0.0,>=0.7.1 Downloading jmespath-1.0.1-py3-none-any.whl (20 kB) Collecting s3transfer<0.7.0,>=0.6.0 Downloading s3transfer-0.6.0-py3-none-any.whl (79 kB) |████████████████████████████████| 79 kB 6.3 MB/s Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /usr/lib/python3.9/site-packages (from botocore<1.30.0,>=1.29.96->boto3) (2.8.1) Collecting urllib3<1.27,>=1.25.4 Downloading urllib3-1.26.15-py2.py3-none-any.whl (140 kB) |████████████████████████████████| 140 kB 7.6 MB/s Requirement already satisfied: six>=1.5 in /usr/lib/python3.9/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.30.0,>=1.29.96->boto3) (1.15.0) Installing collected packages: urllib3, jmespath, botocore, s3transfer, boto3 Successfully installed boto3-1.26.96 botocore-1.29.96 jmespath-1.0.1 s3transfer-0.6.0 urllib3-1.26.15 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv [root@localhost ~]#
Uninstall Package With pip Command
Use given below command to uninstall the package.
sudo pip uninstall python-package-name
[root@localhost ~]# pip uninstall boto3 Found existing installation: boto3 1.26.96 Uninstalling boto3-1.26.96: Would remove: /usr/local/lib/python3.9/site-packages/boto3-1.26.96.dist-info/* /usr/local/lib/python3.9/site-packages/boto3/* Proceed (Y/n)? y Successfully uninstalled boto3-1.26.96 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv [root@localhost ~]#
List Installed Python Modules/Packages
By using pip list
command, you will get the list of installed python modules.
[root@localhost ~]# pip list Package Version --------------- -------- boto3 1.26.96 botocore 1.29.96 dbus-python 1.2.18 gpg 1.15.1 jmespath 1.0.1 libcomps 0.1.18 nftables 0.1 pip 21.2.3 PyGObject 3.40.1 python-dateutil 2.8.1 rpm 4.16.1.3 s3transfer 0.6.0 selinux 3.4 setuptools 53.0.0 six 1.15.0 urllib3 1.26.15 [root@localhost ~]#
The pip Help Section
Use –help switch along with pip command, to get more options. Read the below options, it is quite easy to use.
In this section we will see the available options in pip2.x and pip3.x . If you are working on Python or Pip you must be aware of the change in version could impact your script/work.
We are keeping this section in our record so that fellow programmers could get the benefit of this.
The pip3.x Help Section
The pip3.x help section looks like this. You can easily find the differences in available options compare to pip2.x (It is shown the bottom of this article)
[root@localhost ~]# pip --version pip 21.2.3 from /usr/lib/python3.9/site-packages/pip (python 3.9) [root@localhost ~]# pip --help Usage: pip <command> [options] Commands: install Install packages. download Download packages. uninstall Uninstall packages. freeze Output installed packages in requirements format. list List installed packages. show Show information about installed packages. check Verify installed packages have compatible dependencies. config Manage local and global configuration. search Search PyPI for packages. cache Inspect and manage pip's wheel cache. index Inspect information available from package indexes. wheel Build wheels from your requirements. hash Compute hashes of package archives. completion A helper command used for command completion. debug Show information useful for debugging. help Show help for commands. General Options: -h, --help Show help. --isolated Run pip in an isolated mode, ignoring environment variables and user configuration. -v, --verbose Give more output. Option is additive, and can be used up to 3 times. -V, --version Show version and exit. -q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels). --log <path> Path to a verbose appending log. --no-input Disable prompting for input. --proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port. --retries <retries> Maximum number of retries each connection should attempt (default 5 times). --timeout <sec> Set the socket timeout (default 15 seconds). --exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort. --trusted-host <hostname> Mark this host or host:port pair as trusted, even though it does not have valid or any HTTPS. --cert <path> Path to PEM-encoded CA certificate bundle. If provided, overrides the default. See 'SSL Certificate Verification' in pip documentation for more information. --client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM format. --cache-dir <dir> Store the cache data in <dir>. --no-cache-dir Disable the cache. --disable-pip-version-check Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index. --no-color Suppress colored output. --no-python-version-warning Silence deprecation warnings for upcoming unsupported Pythons. --use-feature <feature> Enable new functionality, that may be backward incompatible. --use-deprecated <feature> Enable deprecated functionality, that will be removed in the future. [root@localhost ~]#
The pip2.x Help Section
sharad@ubuntu:~$ pip --help Usage: pip [options] Commands: install Install packages. uninstall Uninstall packages. freeze Output installed packages in requirements format. list List installed packages. show Show information about installed packages. search Search PyPI for packages. wheel Build wheels from your requirements. zip DEPRECATED. Zip individual packages. unzip DEPRECATED. Unzip individual packages. bundle DEPRECATED. Create pybundles. help Show help for commands. General Options: -h, --help Show help. -v, --verbose Give more output. Option is additive, and can be used up to 3 times. -V, --version Show version and exit. -q, --quiet Give less output. --log-file Path to a verbose non-appending log, that only logs failures. This log is active by default at /home/sharad/.pip/pip.log. --log Path to a verbose appending log. This log is inactive by default. --proxy Specify a proxy in the form [user:passwd@]proxy.server:port. --timeout Set the socket timeout (default 15 seconds). --exists-action Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup. --cert Path to alternate CA bundle. sharad@ubuntu:~$
Why we need pip ?
Through pip we can easily manage the package/modules in Python. You can also consider it as alternate of easy_install
.
Conclusion
In this article, we have learned how to install pip command in Red Hat / Rocky Linux/ Debian/ Ubuntu/ CentOS.
We have also learned to manage the packages with pip command like install,uninstall,list the modules or python packages.
At the end, we have read about the Help section in pip2.x and pip3.x version. Both version has differences in some arguments. This is because of major changes happened in Python 3.x
hi guys !thinks!
Hi,
Regards, this was usefull in my openstackclient installation. Thanks!
So how do you install for 3.5. I have installed 3.5 but pip only works for 2.7
Hello Ryan,
You can try with versioned python command. Let me know the output, it helps to troubleshoot.
This one is to know absolute path
For installing package by pip
Regards
Sharad
Excellent post. It really helped me. Thanks a lot.
Thank you Pavan,
Regards
Sharad
Doesn’t work in 5.4
yum install -y python-pip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: cosmos.cites.illinois.edu
* base: mirror.hmc.edu
* extras: mirror.tocici.com
* updates: mirrors.syringanetworks.net
Setting up Install Process
No package python-pip available.
Nothing to do
Excelent post. It worked perfectly on CentOS 7.
But… on CentOS 5 (64-bits) there is no “python-pip” package. 🙁
Thankyou Alexandre,
Installing from pip source package will work in all supportive OS. 🙂
Regards
Sharad