Search code examples
python-2.7pipopenssl

How to Install pip using python2 / Python (2.x)?


I tried to install libosmesa-devel for my EulerOS. It required Python (2.x) pip to install some packages. I already had python3 installed; so, I installed python2. Then, I got stuck while trying to install pip using python2. The general instruction was to download get-pip.py and run the following command:

python2 get-pip.py

which generates the following error:

Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError('_ssl.c:710: The handshake operation timed out',),)) - skipping
ERROR: Could not find a version that satisfies the requirement pip<21.0 (from versions: none)
ERROR: No matching distribution found for pip<21.0

For the first line of error - SSL certificate error, I tried two approaches:

  1. I rebuild the python-2.7.15-1.x86_64.rpm with ./configure --with-ssl; Did NOT work.
  2. I followed along the following reddit thread but this is from 2021 and I think it is outdated: https://www.reddit.com/r/learnpython/comments/s98n25/comment/htlc7wf/

I tried to use --index-url http://pypi.python.org/simple/ --trusted-host pypi.python.org --trusted-host files.pythonhosted.org arguments to resolve the first error but it did not work.


Solution

  • For the first line of error -

    Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError('_ssl.c:710: The handshake operation timed out',),)) - skipping
    

    Solution: Change https to http in the --index-url http://pypi.python.org/simple/

    So, run ==>

    python2 get-pip.py --index-url http://pypi.python.org/simple/ --trusted-host pypi.python.org --trusted-host files.pythonhosted.org
    

    But this did not solve the following errors -

    ERROR: Could not find a version that satisfies the requirement pip<21.0 (from versions: none)
    ERROR: No matching distribution found for pip<21.0
    

    Solution: Download the following three files from the given links:

    1. pip-20.3.4-py2.py3-none-any.whl
    2. setuptools-44.1.1-py2.py3-none-any.whl
    3. wheel-0.37.1-py2.py3-none-any.whl

    Put these files in the same folder as get-pip.py and run the following command:

    python2 get-pip.py "pip-20.3.4-py2.py3-none-any.whl" "setuptools-44.1.1-py2.py3-none-any.whl" "wheel-0.37.1-py2.py3-none-any.whl" --index-url http://pypi.python.org/simple/ --trusted-host pypi.python.org --trusted-host files.pythonhosted.org
    

    This finally solved the problem!

    Successfully installed pip-20.3.4 setuptools-44.1.1 wheel-0.37.1