简体   繁体   中英

macOS pyenv: pip install not working [SSL: CERTIFICATE_VERIFY_FAILED]

I am trying to install numpy package using pip while working with pyenv (global version 3.8.6).

Command:

pip install numpy

Output:

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1124)'))': /simple/numpy/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1124)'))': /simple/numpy/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1124)'))': /simple/numpy/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1124)'))': /simple/numpy/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1124)'))': /simple/numpy/
Could not fetch URL https://pypi.org/simple/numpy/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/numpy/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1124)'))) - skipping
ERROR: Could not find a version that satisfies the requirement numpy (from versions: none)
ERROR: No matching distribution found for numpy

What I tried to fix this issue:

  • Reinstalling openssl using brew reinstall openssl
  • Reinstalling pyenv using brew reinstall pyenv
  • Reinstalling pyenv-virtualenv using brew reinstall pyenv-virtualenv

When I try to disable pyenv by removing eval "$(pyenv init -)" and eval "$(pyenv virtualenv-init -)" from the ~/.bash_profile , it works fine as it uses the system Python version.

A short term solution is to add --trusted-host pypi.org flag, but I am not sure why it is not working without the flag.

Please help!

As seen here , in previous versions of Python, Apple provided the OpenSSL packages, but they no longer do.

For a temporary fix, add pypi.org as a trusted host (pythonhosted.org actually hosts the files, but they are downloaded from pypi hence why they are also added to the trusted hosts) when using pip:

pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pip setuptools

For a more permanent fix install certifi and Scrapy:

pip install certifi
pip install Scrapy

Similar question 1
Similar question 2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM