Not able to install Python packages [SSL: TLSV1_ALERT_PROTOCOL_VERSION]

前端 未结 17 2021
一整个雨季
一整个雨季 2020-11-21 13:16

I am trying to install a Python library using pip, getting an SSL error:

~/projects/base  pre-master±  pip install xdict

Collecting xdict
  Co         


        
相关标签:
17条回答
  • 2020-11-21 13:55

    Check your TLS version:

    python2 -c "import urllib2,json; print(json.loads(urllib2.urlopen('https://www.howsmyssl.com/a/check').read())['tls_version'])"
    

    If your TLS version is less than 1.2 you have to upgrade it since the PyPI repository is on a brownout period of deprecating early TLS.

    Source - Time To Upgrade Your Python: TLS v1.2 Will Soon Be Mandatory

    You can upgrade the TLS version using the following command:

    sudo apt-get update && sudo apt-get install openssl libssl-dev
    

    This should fix your problem. Good luck!

    EDIT: You can download packages using your own private python package repository regardless of TLS version. Private Python Package Repository

    0 讨论(0)
  • 2020-11-21 13:57

    I tried all existing fixes and not working for me

    I re-install python 2.7 (will also install pip) by downloading .pkg at https://www.python.org/downloads/mac-osx/

    works for me after installation downloaded pkg

    0 讨论(0)
  • 2020-11-21 13:59

    The answers of installing pip via:

    1. curl https://bootstrap.pypa.io/get-pip.py |sudo python or
    2. curl https://bootstrap.pypa.io/get-pip.py | python

    did not work for me as I kept on getting the 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("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
    ERROR: Could not find a version that satisfies the requirement pip (from versions: none)
    ERROR: No matching distribution found for pip
    

    I had to install pip manually via:

    1. Go the pip distribution website
    2. Download the tar.gz version
    3. Unpack the file locally and cd into the directory
    4. run python setup.py install
    0 讨论(0)
  • 2020-11-21 14:03

    To upgrade the local version I used a slight variant:

    curl https://bootstrap.pypa.io/get-pip.py | python - --user
    

    This problem arises if you keep your pip and packages under your home directory as described in this gist.

    0 讨论(0)
  • 2020-11-21 14:04

    The following solution worked for me:

    brew install python2
    

    It also upgraded pip to version 1.10.1

    0 讨论(0)
提交回复
热议问题