How to install pip on Red Hat Enterprise Linux?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7
  • Red Hat Software Collections

Issue

Is the pip available in RHSCL for RHEL6 and RHEL7?

Resolution

WARNING: Using pip as root user can OVERWRITE your system python libraries, use a virtualenv as a normal user whenever possible to avoid issues when packages are upgraded using Red Hat provided RPM's.

  • For RHEL6, python27-python-pip is available in RHSCL(Red Hat Software Collections) 2.0. Refer to RHBZ#994189 for all history regarding the package and RHSA-2015-1064 is the errata announcement.
  • For RHEL7, pip for python2 and python3 are available in RHSCL too. Please obtain the packages by enabling the RHSCL repository.

  • Here are some example steps for RHEL7:

    1. Install the pip from SCL as root

      # subscription-manager repos --enable rhel-server-rhscl-7-rpms
      # yum install python27-python-pip
      
    2. Switch to a normal user and check the pip

      $ scl enable python27 bash
      $ which pip
      $ pip -V
      

Note: When you close the current bash you will need to run the scl enable command again as the change is not persistent, more info about that can be found here

Diagnostic Steps

Verify the following commands:

$  rpm -qf /bin/scl
scl-utils-20130529-18.el7_4.x86_64

$ scl -l
python27

$ scl enable python27 bash

$which pip
/opt/rh/python27/root/usr/bin/pip

$ pip -V
pip 8.1.2 from /opt/rh/python27/root/usr/lib/python2.7/site-packages (python 2.7)

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

6 Comments

Python virtual environments are the best way to avoid problem with installing Python modules. Also pip --user can be used to install modules in a user's home directory under their normal user ID without requiring root. Virtual environments are better because they allow you to isolate project specific dependencies.

For instructions and tips covering pip, virtualenv, venv, pipenv, and Python software collections see this article on developers.redhat.com.

[root@hostname01 ~]# pip install pyvim pyVmomi Collecting pyvim Exception: Traceback (most recent call last): File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/commands/install.py", line 307, in run requirement_set.prepare_files(finder) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 370, in prepare_files ignore_dependencies=self.ignore_dependencies)) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 587, in _prepare_file session=self.session, hashes=hashes) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/download.py", line 810, in unpack_url hashes=hashes File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/download.py", line 649, in unpack_http_url hashes) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/download.py", line 842, in _download_http_url stream=True, File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 487, in get return self.request('GET', url, **kwargs) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/download.py", line 378, in request return super(PipSession, self).request(method, url, *args, **kwargs) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 475, in request resp = self.send(prep, **send_kwargs) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 585, in send r = adapter.send(request, **kwargs) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/_vendor/cachecontrol/adapter.py", line 46, in send resp = super(CacheControlAdapter, self).send(request, **kw) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.py", line 477, in send raise SSLError(e, request=request) SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)

Hi,

I'd recommend opening up a new support case for that issue so support can verify what is going wrong there.

As a start: There is most likely an issue starting a new HTTPS connection to pypi.python.org

You could also add a parameter to add the host to trusted hosts:

  --trusted-host <hostname>   Mark this host as trusted, even though it does not have valid or any HTTPS.

Add the following output to the case

# pip search vim -vvv

[root@linuxtmp74 certs]# which pip /opt/rh/python27/root/usr/bin/pip [root@linuxtmp74 certs]# pip -V pip 8.1.2 from /opt/rh/python27/root/usr/lib/python2.7/site-packages (python 2.7) [root@linuxtmp74 certs]# pip search vim -vvv Starting new HTTPS connection (1): pypi.python.org Exception: Traceback (most recent call last): File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/commands/search.py", line 43, in run pypi_hits = self.search(query, options) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/commands/search.py", line 60, in search hits = pypi.search({'name': query, 'summary': query}, 'or') File "/opt/rh/python27/root/usr/lib64/python2.7/xmlrpclib.py", line 1243, in call return self.__send(self.__name, args) File "/opt/rh/python27/root/usr/lib64/python2.7/xmlrpclib.py", line 1602, in __request verbose=self.__verbose File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/download.py", line 764, in request headers=headers, stream=True) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 518, in post return self.request('POST', url, data=data, json=json, **kwargs) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/download.py", line 378, in request return super(PipSession, self).request(method, url, *args, **kwargs) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 475, in request resp = self.send(prep, **send_kwargs) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 585, in send r = adapter.send(request, **kwargs) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/_vendor/cachecontrol/adapter.py", line 46, in send resp = super(CacheControlAdapter, self).send(request, **kw) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.py", line 477, in send raise SSLError(e, request=request) SSLError: [Errno 2] No such file or directory Looking up "https://pypi.python.org/pypi/pip/json" in the cache No cache entry available Starting new HTTPS connection (1): pypi.python.org There was an error checking the latest version of pip Traceback (most recent call last): File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/utils/outdated.py", line 126, in pip_version_check headers={"Accept": "application/json"}, File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 487, in get return self.request('GET', url, **kwargs) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/download.py", line 378, in request return super(PipSession, self).request(method, url, *args, **kwargs) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 475, in request resp = self.send(prep, **send_kwargs) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 585, in send r = adapter.send(request, **kwargs) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/_vendor/cachecontrol/adapter.py", line 46, in send resp = super(CacheControlAdapter, self).send(request, **kw) File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.py", line 477, in send raise SSLError(e, request=request) SSLError: [Errno 2] No such file or directory [root@linuxtmp74 certs]# pip install --upgrade pip Could not fetch URL https://pypi.python.org/simple/pip/: There was a problem confirming the ssl certificate: [Errno 2] No such file or directory - skipping Requirement already up-to-date: pip in /opt/rh/python27/root/usr/lib/python2.7/site-packages [root@linuxtmp74 certs]#

When I type

subscription-manager repos --enable rhel-server-rhscl-7-rpms

I get the following error:

Error: 'rhel-server-rhscl-7-rpms' does not match a valid repository ID. Use "subscription-manager repos --list" to see valid repositories. I have tried the following with no luck:

subscription-manager unregister subscription-manager clean yum clean all subscription-manager register --auto-attach
subscription-manager repos --list

doesn't show this repo in the list.

Thanks, Dave

Hi, that probably means that your current subscriptions do not provide access to RHSCL. You can go trough request access to RHSCL