Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSL: CERTIFICATE_VERIFY_FAILED error from Python pip in Ubuntu 16.0.4

Python pip suddenly stopped working and it gives SSL: CERTIFICATE_VERIFY_FAILED error.
I am not able to install any of the pip packages.
sudo pip install scikit-image is throwing following error

Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)'),)': /simple/scikit-image/
Could not fetch URL https://pypi.python.org/simple/scikit-image/: There was a problem confirming the ssl certificate:
HTTPSConnectionPool(host='pypi.python.org', port=443): Max retries exceeded with url: /simple/scikit-image/ (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)'),)) - skipping

I tried using easy_install but it is giving the same SSL error.
When I tried downloading a zip file of 5GB using wget , the downloaded file size is in KBs
Can someone please suggest the solution for above problem.

Thank You

like image 439
Aishwarya Avatar asked Mar 28 '18 17:03

Aishwarya


People also ask

What is SSL certificate Python requests?

Requests verifies SSL certificates for HTTPS requests, just like a web browser. SSL Certificates are small data files that digitally bind a cryptographic key to an organization's details. Often, a website with a SSL certificate is termed as secure website.


1 Answers

It can be related to the recent change of PyPI domains.
Public announcements of the change:
https://pyfound.blogspot.com/2018/03/warehouse-all-new-pypi-is-now-in-beta.html
https://pyfound.blogspot.com/2017/01/time-to-upgrade-your-python-tls-v12.html

If you run pip from behind proxy/firewall, please ensure it allows access to/from:

  • pypi.org
  • files.pythonhosted.org

Also you may give a try to certain pip options:
$ python -m pip <command> --trusted-host files.pythonhosted.org --trusted-host pypi.org --trusted-host pypi.python.org ... --proxy ...

In case there is a problem with outdated OS root certificates, pip uses urllib3 and certifi libraries for SSL certificate verification and TLS connection. You could give it a try:
$ pip install --user --trusted-host files.pythonhosted.org --trusted-host pypi.org --trusted-host pypi.python.org certifi

If still no-go, browse to PyPI.org and download the python certifi package from its "Download Files" section, and install manually:
$ pip install --user --no-index ~/Downloads/certifi-2018.11.29-py2.py3-none-any.whl

By the way, unlike with sudo apt, running sudo pip install command with root access to install or upgrade Python packages is not recommended, because it interferes with your OS package manager subsystem (apt,yum,etc) and may affect essential OS (Ubuntu,Debian,Fedora,etc) components that depend upon your system python. The --user flag allows to install packages to your home dir (under ~/.local/lib); else you could use virtualenv.

And for the system-wide package deployments, Ubuntu expects us to use apt package manager. There are many (not all) python packages, including scikit that you needed – just use $ apt search (same as older $ apt-cache search) to find it, $ apt show for package description, and $ sudo apt install to install.

like image 193
Alex C. Avatar answered Sep 18 '22 18:09

Alex C.