Question
When running # python -m pip --version
, I do not see a version returned. How can I install Python pip?
Answer
For CentOS 6/7, CloudLinux 6/7, and Red Hat Enterprise Linux 6./7, Python requires python2-pip to be installed in order to use the pip package. There is two option to get pip.
Because the package is not part of the default repository, you can use epel-release to get the package; however, EPEL has an older version, 8.1.
# python -m pip --version
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)
# yum install epel-release
# yum install python2-pip
As an alternative option, if you need a newer version, we can use the official python script "get-pip.py" which automatically pulls the latest compatible version of pip needed for your server. Python2.7 stopped supporting pip beyond version21, and the script will install 20.3.4 on a server running Python 2.7 and CentOS7.
# curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py
# python get-pip.py
# python -m pip install --upgrade "pip < 21.0"
For CentOS 8, Cloud Linux 8, or AlmaLinux 8, these use python3, so we need to install python3-pip instead of python2-pip if it is not present.
# dnf install python3-pip
Then, # python3 -m pip --version
to verify the version.
# python3 -m pip --version
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)
If you need to upgrade this version, you can use the main get-pip.py script:
# curl -O https://bootstrap.pypa.io/pip/get-pip.py
# python3 get-pip.py
For 20.3.4, run:
# python3 -m pip install --upgrade "pip < 21.0"
For 21.1.3, run
# python3 -m pip install --upgrade "pip > 21.0"