680

I am very new to Python and trying to > pip install linkchecker on Windows 7. Some notes:

  • pip install is failing no matter the package. For example, > pip install scrapy also results in the SSL error.
  • Vanilla install of Python 3.4.1 included pip 1.5.6. The first thing I tried to do was install linkchecker. Python 2.7 was already installed, it came with ArcGIS. python and pip were not available from the command line until I installed 3.4.1.
  • > pip search linkchecker works. Perhaps that is because pip search does not verify the site's SSL certificate.
  • I am in a company network but we do not go through a proxy to reach the Internet.
  • Each company computer (including mine) has a Trusted Root Certificate Authority that is used for various reasons including enabling monitoring TLS traffic to https://google.com. Not sure if that has anything to do with it.

Here are the contents of my pip.log after running pip install linkchecker:

Downloading/unpacking linkchecker
  Getting page https://pypi.python.org/simple/linkchecker/
  Could not fetch URL https://pypi.python.org/simple/linkchecker/: connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)
  Will skip URL https://pypi.python.org/simple/linkchecker/ when looking for download links for linkchecker
  Getting page https://pypi.python.org/simple/
  Could not fetch URL https://pypi.python.org/simple/: connection error: HTTPSConnectionPool(host='pypi.python.org', port=443): Max retries exceeded with url: /simple/ (Caused by <class 'http.client.CannotSendRequest'>: Request-sent)
  Will skip URL https://pypi.python.org/simple/ when looking for download links for linkchecker
  Cannot fetch index base URL https://pypi.python.org/simple/
  URLs to search for versions for linkchecker:
  * https://pypi.python.org/simple/linkchecker/
  Getting page https://pypi.python.org/simple/linkchecker/
  Could not fetch URL https://pypi.python.org/simple/linkchecker/: connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)
  Will skip URL https://pypi.python.org/simple/linkchecker/ when looking for download links for linkchecker
  Could not find any downloads that satisfy the requirement linkchecker
Cleaning up...
  Removing temporary dir C:\Users\jcook\AppData\Local\Temp\pip_build_jcook...
No distributions at all found for linkchecker
Exception information:
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\pip\basecommand.py", line 122, in main
    status = self.run(options, args)
  File "C:\Python34\lib\site-packages\pip\commands\install.py", line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "C:\Python34\lib\site-packages\pip\req.py", line 1177, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "C:\Python34\lib\site-packages\pip\index.py", line 277, in find_requirement
    raise DistributionNotFound('No distributions at all found for %s' % req)
pip.exceptions.DistributionNotFound: No distributions at all found for linkchecker
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Jeremy Cook
  • 20,840
  • 9
  • 71
  • 77
  • 1
    Quite the opposite! Python 3.4.1 and earlier do not do certificate validation by default. If you were using Python 3.4.2, I would have thought that was the problem. (See [issue 21013](http://bugs.python.org/issue21013) and [this thread on the mailing list](https://mail.python.org/pipermail/python-dev/2014-August/136034.html). Note that that is the beginning of a pretty long thread.) Sorry I couldn't actually help! – Cody Piersall Sep 26 '14 at 14:51
  • http://superuser.com/a/747127/13889 – endolith Aug 09 '16 at 21:27
  • 3
    Check if you have fiddler opened and close it. Fiddler try break SSL and this breaks pip, when I close fiddler pip works for me. [When I close my fiddler everything goes ok](http://i.stack.imgur.com/5Z1V6.png) – Jose Barbosa Jul 07 '16 at 04:46
  • You should reinstall Xcode command line tools that contains Python. https://stackoverflow.com/a/68247505/4067700 – Victor Kushnerov Jul 05 '21 at 08:41
  • This problem happens in linux when not using `sudo` inside a venv. (if anyone had this problem in linux) – Deera Wijesundara Mar 18 '22 at 10:57

57 Answers57

1059

UPDATE: 2023-08: pip.conf does not have a field for sslverify false. this may have worked years ago but does not work today.


use trusted-host in either pip.conf or command line argument

You can ignore SSL errors by setting pypi.org and files.pythonhosted.org as well as the older pypi.python.org as trusted hosts.

$ pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org <package_name>

Note: Sometime during April 2018, the Python Package Index was migrated from pypi.python.org to pypi.org. This means "trusted-host" commands using the old domain no longer work, but you can add both.

Permanent Fix

Since the release of pip 10.0, you should be able to fix this permanently just by upgrading pip itself:

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

Or by just reinstalling it to get the latest version:

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

(… and then running get-pip.py with the relevant Python interpreter).

pip install <otherpackage> should just work after this. If not, then you will need to do more, as explained below.


You may want to add the trusted hosts and proxy to your config file.

pip.ini (Windows) or pip.conf (unix)

[global]
trusted-host = pypi.python.org
               pypi.org
               files.pythonhosted.org

Alternate Solutions (Less secure)

Most of the answers could pose a security issue.

Two of the workarounds that help in installing most of the python packages with ease would be:

  • Using easy_install: if you are really lazy and don't want to waste much time, use easy_install <package_name>. Note that some packages won't be found or will give small errors.
  • Using Wheel: download the Wheel of the python package and use the pip command pip install wheel_package_name.whl to install the package.
Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177
Vaulstein
  • 20,055
  • 8
  • 52
  • 73
  • 8
    Your update got things going for me. In my case the corporate firewall inserts itself as the trusted host for SSL connections. I assumed proxy setup was wrong but adding verbose showed the issue was SSL. The index-url change worked around the issue. – peater Sep 25 '15 at 18:40
  • 14
    Awesome, thx! The trusted-host seems to be sufficient, ie. `pip install --trusted-host pypi.python.org pypi_package`. Using `--verbose` shows that without `--trusted-host`, the HTTPS connection fails, whereas the same HTTPS connection is attempted (not HTTP) with `--trusted-host` but it succeeds. – Oliver Dec 22 '15 at 19:18
  • 16
    Isn't using the HTTP version (and then even trusting it) also a security risk? – Paŭlo Ebermann Jun 24 '16 at 11:47
  • 3
    you can make it as short to ignore the --index-url parameter ,try this command also should be ok : `pip install --trusted-host pypi.python.org pythonPackage` – Alter Hu Aug 23 '16 at 04:43
  • "pip install --trusted-host pypi.python.org " worked for me. Thanks! – FistOfFury Feb 27 '17 at 14:30
  • 1
    Can you separate your old answer out into a separate post? Haveing more than one answer in a single post is a bit confusing – Stevoisiak Oct 16 '17 at 20:09
  • 1
    Not working > Could not fetch URL http://pypi.python.org/simple/{packet}/: 403 Client Error: SSL is required for url: http://pypi.python.org/simple/{packet}/ - skipping – Alex78191 Oct 28 '17 at 06:06
  • I got "no such option: --trusted-host" but I solved it by using "easy_install pip==9.0.1" I was using pip 1.5.6 when I got the error – DevB2F Nov 15 '17 at 23:36
  • Pypi.python.org only accept https connection now. So must be `--index-url=https://pypi.python.org/simple/` – Joao Vitorino Feb 09 '18 at 14:09
  • 1
    If you are lazy like me and prefer working within the IDE (PyCharm in my case), you can add the option by Checking the "Options" box in the Available Packages window and type "--trusted-host pypi.python.org". – Matthew Weber Feb 28 '18 at 16:49
  • This is a hack, not a solution. Most of the time, if you are using setup scripts using pip...you won't edit each of those one – sancelot Mar 13 '18 at 07:51
  • 10
    it does not work for me. Running mac os high sierra on a macbookpro 15" Python 2.7 pip 9.0.1 I Tried both: sudo -H pip install --trusted-host pypi.python.org numpy and sudo pip install --trusted-host pypi.python.org numpy it always gives me the same error: "There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661) - skipping Could not find a version that satisfies the requirement" – DaniPaniz Apr 11 '18 at 18:55
  • @DaniPaniz You can download the .dmg file for [numpy](https://sourceforge.net/projects/numpy/files/NumPy/) and install it on Mac – Vaulstein Apr 12 '18 at 11:28
  • @DaniPaniz *Could not find a version that satisfies the requirement* errors can come for the following reason: *System time is way off (before 2014-01-01). This will probably lead to SSL verification errors* See link - https://stackoverflow.com/questions/43127536/pip-error-could-not-find-a-version-that-satisfies-the-requirement-junos-eznc – Vaulstein Apr 12 '18 at 11:34
  • @Vaulstein thanks for the advice but nothing works. (I know I can install pygame via the dmg but I can't install anything else with pip). I tried every hack and it still doesn't work. Can I uninstall it and reinstall the 1.2 version which apparently does not give this problem? – DaniPaniz Apr 12 '18 at 14:18
  • I'm reading this link: https://github.com/Homebrew/legacy-homebrew/issues/41253 and I think the problem might be that the SSL certificate is in another folder with respect to the one pip is looking for.. – DaniPaniz Apr 12 '18 at 14:25
  • 1
    updatE: i just deleted pip and python 2.7. Reinstalled both (using brew with python) and now it magically works. probably the links were messed up.. thanks :D – DaniPaniz Apr 12 '18 at 14:34
  • 2
    On CentOS 7.4, I had to add all of the following hosts as trusted as evidently the pypi.python.org requests leads to requests to the other two: --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org – ScoPi Apr 18 '18 at 16:07
  • For me (Mac OS X High Sierra), the best way to get around this is to use pip download -d and then pip install --no-index --find-links . – Shawn Apr 18 '18 at 17:04
  • As of now when pip has upgraded to 10 and now they have changed their path to files.pythonhosted.org Please update the command to pip --trusted-host files.pythonhosted.org install <> – Shivam Kotwalia Apr 23 '18 at 10:25
  • I had a parser error on `trusted-host pypi.python.org` which I changed to `trusted-host: pypi.python.org` (with the `:`) to get working. – Matthew Rasa May 03 '18 at 13:27
  • Even after configuring `pip.ini` accordingly, `pip` and `pip3` continue to present the same SSL certificate validation error in Windows 10. – mcandre May 13 '18 at 23:26
  • I've set it up, but now I'm beeing required to login: `User for files.pythonhosted.org:`. – Joabe Lucena Jun 07 '18 at 14:50
  • 2
    `pip install --trusted-host pypi.python.org --trusted-host pypi.org ` works for me. The old pypi.python.org forwards to pypi.org, so you need both. The `--verbose` flag led me through. – JimB Jun 15 '18 at 00:01
  • Thanks :> I was installing a package behind a proxy without admin rights, took me foreve to figure this out. `(path_to_python)\python.exe -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org --proxy=http://(proxy's IP and port) (package name)` – Skrmnghrd Nov 21 '18 at 03:36
  • trusted-host does not fix the SSL error in Win10, either in pip.ini nor as a CLI flag :/ – mcandre Jan 14 '19 at 04:44
  • @mcandre Have you tried using wheel to install packages then as suggested in the answer? – Vaulstein Jan 14 '19 at 06:06
  • 1
    @Vaulstein In my case, the problem turned out not to be pip or PyPI at all, but rather a specific package. The bashate package appears to download artifacts from an unaffiliated domain, and Windows gets confused somehow. – mcandre Jan 23 '19 at 19:53
  • @mcandre Thanks! this could help someone looking to install bashate package. – Vaulstein Jan 24 '19 at 06:00
  • this all did not work unless we upgraded the libssl! `sudo apt-get update && sudo apt-get install --only-upgrade libssl-dev` – sunsetjunks Mar 26 '19 at 10:31
  • In fact, this answer fixed my problem, I'm in a corporate network with **BueCoat** as proxy, all certificates are replaced by my proxy, so very often we have certificate problems, the way easy to solve this is ignoring certificates problems, I'm note sure if is the safe way. – Roberto Borges May 15 '19 at 14:58
  • @Vaulstein: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org worked for me Thanks ! . Is there any equivalent command which would work for YARN ? – Akash Patil May 20 '19 at 08:53
  • @Vaulstein: Yes – Akash Patil May 21 '19 at 11:21
  • If I need to use -i parameter, it does not seem to work for me. Works great otherwise. Is there a solution for a different -i parameter? – demongolem May 21 '19 at 15:21
  • This is a very irresponsible answer. If pypi's domain ever gets maliciously taken over, anyone who has used your solution won't see the connection error (seeing an SSL error is a good thing in this case) – mmla May 30 '19 at 16:09
  • @mmla a package on pypi could also be replaced with malicious code. How would a someone deal with that then? – Vaulstein May 31 '19 at 07:30
  • Creating the .ini file in Windows (Users//AppData/Roaming/pip/pip.ini in a text editor with that little bit of text just as you wrote it above worked for me like nothing else has in this long drawn out excruciating painful experience!!! – jbchurchill Nov 01 '19 at 13:43
  • on rhel8 this worked for me. 1. pip2 install mysql-connector-python and then 2. pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org mysql-connector-python – Santosh Pillai Nov 05 '19 at 10:00
  • For me pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org worked – Adil Mar 23 '20 at 19:33
  • "http.sslVerify" doesn't exist (at least in current pip versions), it is not a valid option! I would edit the answer, but the edit-queue ist full... – volkit Jun 09 '21 at 15:30
  • Although I was in a hurry and this solution worked for me, when I had time I was able to check that the problem actually was with my certificates. I was using a virtual machine with Kubuntu and I had my `/etc/ssl/certs/ca-certificates.crt` empty. I don't know the reason why suddenly the content of the file was removed, but restoring that file was the solution, and I guess it is better solution than this which it is said to be insecure. Anyway, thanks! – forvas Oct 20 '21 at 12:46
204

Use the --cert argument:

You can specify a certificate with:

pip --cert <path/to/cert>.pem install <package list>

e.g.:

pip --cert /etc/ssl/certs/FOO_Root_CA.pem install linkchecker

See: Docs » Reference Guide » pip

If specifying your company's root cert doesn't work maybe the cURL one will work: http://curl.haxx.se/ca/cacert.pem

You must use a PEM file and not a CRT file. If you have a CRT file you will need to convert the file to PEM There are reports in the comments that this now works with a CRT file but I have not verified.

Also check: SSL Cert Verification.

Stabledog
  • 3,110
  • 2
  • 32
  • 43
Steve Tauber
  • 9,551
  • 5
  • 42
  • 46
  • Thanks Steve. I saw that doc, and that does seem like a likely solution to my problem. I'm on Windows 7, do not have a pem file, and am unwilling to use a pem from some third party (can that be secure!?). How can I create a **pem** file that gets the job done? – Jeremy Cook Sep 26 '14 at 15:08
  • 1
    The Curl one IS secure. I would suggest using that. – Steve Tauber Sep 29 '14 at 10:18
  • I ran the command using the Curl cert and got the same errors. – Jeremy Cook Sep 29 '14 at 20:53
  • @JeremyCook Could you show how exactly did you ran the command with Curl cert? Did you download the curl certificate to your local disk and passed the filesystem path to the `--cert` argument? I don't think that `--cert` supports urls. The requested page is signed by DigiCert and curl CA contains DigiCert so it would be very strange if it doesn't work with curl. – Piotr Sobczyk Oct 01 '14 at 18:34
  • @PiotrSobczyk I downloaded the cert from https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt and ran `pip --cert C:\Python32\ca-bundle.crt install linkchecker`. It resulted in the same "connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)" error. – Jeremy Cook Oct 01 '14 at 20:20
  • 1
    @JeremyCook it could be the time on your server, if it is in the past it could be the verifying process – Giovanni Bitliner Jan 26 '15 at 20:32
  • 1
    CRT format is not supported, only PEM format is. You will need to convert the CRT to PEM format using openssl. You should also verify that the bundle that you've downloaded contains the correct root CA. Please see my answer above for the details: http://stackoverflow.com/a/28724886/41957. – chnrxn Feb 28 '15 at 14:38
  • 1
    @JeremyCook, the PEM/certs did not come directly from the third party that you downloaded them from. They gathered the certs from the original sources. It is not possible for a 3rd party to generate a certificate of someone else unless they have the correct key (which only the someone else will have). – chnrxn Feb 28 '15 at 14:43
  • 4
    @endolith - Looking at https://pip.pypa.io/en/stable/user_guide/#configuration it looks like you can either use environment variables, or a `pip.conf` file to have them referenced permanently without specifying on the command – Cinderhaze Apr 24 '18 at 13:30
  • 4
    Works with `.crt` well now – Jan Sila Feb 07 '19 at 13:07
  • For me, neither the downloaded cacert.pem nor my company's root certificate worked. However, adding the company root certificate to the downloaded cacert.pem did the trick. My company uses a proxy though, so my use case is slightly different. – CrouZ Oct 19 '21 at 09:48
  • @chnrxn "CRT format is not supported, only PEM format is" - `crt` is not a format, it's a common ad-hoc file extension for certificates that says nothing about which format they are in. Many OS-shipped CA bundles are in PEM format *and* have a `.crt` file extension. – jbg Jun 03 '23 at 04:32
134

For me the problem was fixed by creating a folder pip, with a file: pip.ini in C:\Users\<username>\AppData\Roaming\ e.g:

C:\Users\<username>\AppData\Roaming\pip\pip.ini

Inside it I wrote:

[global]
trusted-host = pypi.python.org
               pypi.org
               files.pythonhosted.org

I restarted python, and then pip permanently trusted these sites, and used them to download packages from.

If you can't find the AppData Folder on windows, write %appdata% in file explorer and it should appear.

Timo Kvamme
  • 2,806
  • 1
  • 19
  • 24
  • 1
    Strangely this is not helping on my Win10 machine :/ – mcandre Jan 14 '19 at 04:46
  • 2
    At work, Windows 10 environment, using Cmder console emulator. --trusted-host used to resolve the "'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain" issue. Today it stopped working. I placed a copy of my pip folder (taken from ../AppData/Local/ ) in ../AppData/Roaming/ and all is right with my local python world again. Thanks much! – IdusOrtus May 03 '19 at 16:00
  • 1
    Great! Thank you very much. --trusted-host doesn't work for me now, but your solution helps. – Alexander Prokofyev Sep 13 '19 at 12:05
  • 2
    Why wasn't this downloaded when installing Python> – Eduards Oct 30 '19 at 18:11
  • Awesome! I was searching for errors related with GIT, company's proxy, SSL and it just was pip related. Thank you and I hope this comment bring here people confused like me. – negas Dec 27 '19 at 15:20
  • 1
    One other location: %programdata%/pip/pip.ini – Vasantha Ganesh Jan 25 '21 at 06:35
  • 1
    I thought this was something my company Info security was blocking for long time and hours spent researching this. At the end of the day, to download new python libraries this is the only thing i have to do. Create this pip.ini file and copy/paste the code above and it worked perfectly!! Thanks – Matthew Myers Nov 17 '21 at 16:42
  • Thanks! This solution worked with windows10 "certificate verify failed: self signed certificate in certificate chain" error. – watopin Jun 14 '22 at 04:43
  • 1
    Thanks a bunch!! This is an easy fix and I would recommend all the users to follow this. – Sayed Sadat Jul 18 '22 at 05:42
  • This worked. Most important step is that the pip folder must be placed under "AppData\roaming" not "AppData\Local" – Viknesh S K Jan 06 '23 at 12:39
130

Permanent fix - pip config

I had ssl issues due to company network security related to netscope. My machine is windows 10 with python 3.9 and the following command worked for me.

pip config set global.trusted-host \
    "pypi.org files.pythonhosted.org pypi.python.org" \
    --trusted-host=pypi.python.org \
    --trusted-host=pypi.org \
    --trusted-host=files.pythonhosted.org

Here, pip permanently trusted these sites, and now we can use them to download any packages.

Gringo Suave
  • 29,931
  • 6
  • 88
  • 75
nirojshrestha019
  • 2,068
  • 1
  • 10
  • 14
73

kenorb’s answer is very useful (and great!).
Among his solutions, maybe this is the most simple one: --trusted-host

For example, in this case you can do

pip install --trusted-host pypi.python.org linkchecker

The pem file(or anything else) is unnecessary.

Community
  • 1
  • 1
plhn
  • 5,017
  • 4
  • 47
  • 47
  • This also works for other commands such as `pip list --trusted-host pypi.python.org --outdated` – Igor Aug 17 '17 at 15:50
58

The answers are quite similar and a bit confusing. In my case, the certificates in my company's network was the issue. I was able to work around the problem using:

pip install --trusted-host files.pythonhosted.org --trusted-host pypi.org --trusted-host pypi.python.org oauthlib -vvv

As seen here. The -vvv argument can be omited if verbose output is not required

Koji D'infinte
  • 1,309
  • 12
  • 20
  • Works because today I am behind some proxy that strips out normal SSL. I don't normally need to specify trusted hosts when grown ups run the network. – MrChrister Dec 10 '19 at 21:05
55

I tried majority of the solutions provided in this answer blog, however none of them worked, I had this ssl certificant error as I try to install python packages.

I succeed by following command:

python -m pip install PACKAGENAME --trusted-host=pypi.python.org --trusted-host=pypi.org --trusted-host=files.pythonhosted.org 
Weilory
  • 2,621
  • 19
  • 35
  • 3
    you are a God/dess – AofWessex Dec 31 '20 at 23:05
  • After lot of searching finally this did it. Turns out if you are on corporate network they sometimes mess with your SSL or certificates or could be something to do with firewall / proxy. Try with mobile hotspot or something if you have wi-fi adapter which also works for me. – Canute S Aug 19 '21 at 17:31
  • You are a legend.. After full day of searching for solution, this one is working. – Moses Feb 23 '23 at 13:21
  • this was the only one that worked for me as well – joejoejoejoe4 Apr 10 '23 at 16:56
49

Permanent Fix

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

For eg:

pip install <package name> --trusted-host pypi.org --trusted-host files.pythonhosted.org
Devesh Sharma
  • 949
  • 11
  • 14
28

The most straightforward way I've found, is to download and use the "DigiCert High Assurance EV Root CA" from DigiCert at https://www.digicert.com/digicert-root-certificates.htm#roots

You can visit https://pypi.python.org/ to verify the cert issuer by clicking on the lock icon in the address bar, or increase your geek cred by using openssl:

$ openssl s_client -connect pypi.python.org:443
CONNECTED(00000003)
depth=1 /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert SHA2 Extended Validation Server CA
verify error:num=20:unable to get local issuer certificate
verify return:0
---
Certificate chain
 0 s:/businessCategory=Private Organization/1.3.6.1.4.1.311.60.2.1.3=US/1.3.6.1.4.1.311.60.2.1.2=Delaware/serialNumber=3359300/street=16 Allen Rd/postalCode=03894-4801/C=US/ST=NH/L=Wolfeboro,/O=Python Software Foundation/CN=www.python.org
   i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert SHA2 Extended Validation Server CA
 1 s:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert SHA2 Extended Validation Server CA
   i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV Root CA

The last CN value in the certificate chain is the name of the CA that you need to download.

For a one-off effort, do the following:

  1. Download the CRT from DigiCert
  2. Convert the CRT to PEM format
  3. Export the PIP_CERT environment variable to the path of the PEM file

(the last line assumes you are using the bash shell) before running pip.

curl -sO http://cacerts.digicert.com/DigiCertHighAssuranceEVRootCA.crt 
openssl x509 -inform DES -in DigiCertHighAssuranceEVRootCA.crt -out DigiCertHighAssuranceEVRootCA.pem -text
export PIP_CERT=`pwd`/DigiCertHighAssuranceEVRootCA.pem

To make this re-usable, put DigiCertHighAssuranceEVRootCA.crt somewhere common and export PIP_CERT accordingly in your ~/.bashrc.

chnrxn
  • 1,349
  • 1
  • 16
  • 17
  • 4
    Used your answer to export our company's root CA to the PIP_CERT variable and finally after trying everything else including 'pip --cert cert.pem' your way worked...just pip install package. BIG +1 - yeah we have a firewal/proxy/utm. – Marlon Mar 22 '16 at 17:58
  • This still failed for me on Mac Mojave. I followed exactly the 3 steps and still I get "Error: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available". I tried all the --trusted-host and --cert options and pip will not work. I tried to upgrade pip and got the SSL error. I installed pip from scratch with curl and still I get the error when I run pip. Time to ditch pip and stick to conda :( – user1255933 Mar 31 '20 at 21:57
28

To solve this problem once and for all, you can verify that you have a pip.conf file.

This is where your pip.conf should be, according to the documentation:

On Unix the default configuration file is: $HOME/.config/pip/pip.conf which respects the XDG_CONFIG_HOME environment variable.

On macOS the configuration file is $HOME/Library/Application Support/pip/pip.conf if directory $HOME/Library/Application Support/pip exists else $HOME/.config/pip/pip.conf

On Windows the configuration file is %APPDATA%\pip\pip.ini.

Inside a virtualenv:

On Unix and macOS the file is $VIRTUAL_ENV/pip.conf

On Windows the file is: %VIRTUAL_ENV%\pip.ini

Your pip.conf should look like:

[global]
trusted-host = pypi.python.org

pip install linkchecker installed linkchecker without complains after I created the pip.conf file.

Community
  • 1
  • 1
Alex Fortin
  • 2,105
  • 1
  • 18
  • 27
27

You've the following possibilities to solve issue with CERTIFICATE_VERIFY_FAILED:

  • Use HTTP instead of HTTPS (e.g. --index-url=http://pypi.python.org/simple/).
  • Use --cert <trusted.pem> or CA_BUNDLE variable to specify alternative CA bundle.

    E.g. you can go to failing URL from web-browser and import root certificate into your system.

  • Run python -c "import ssl; print(ssl.get_default_verify_paths())" to check the current one (validate if exists).

  • OpenSSL has a pair of environments (SSL_CERT_DIR, SSL_CERT_FILE) which can be used to specify different certificate databasePEP-476.
  • Use --trusted-host <hostname> to mark the host as trusted.
  • In Python use verify=False for requests.get (see: SSL Cert Verification).
  • Use --proxy <proxy> to avoid certificate checks.

Read more at: TLS/SSL wrapper for socket objects - Verifying certificates.

kenorb
  • 155,785
  • 88
  • 678
  • 743
21

Set Time and Date correct!

For me, it came out that my date and time was misconfigured on Raspberry Pi. The result was that all SSL and HTTPS connections failed, using the https://files.pythonhosted.org/ server.

Update it like this:

sudo date -s "Wed Thu  23 11:12:00 GMT+1 2018"
sudo dpkg-reconfigure tzdata

Or directly with e.g. Google's time:

Ref.: https://superuser.com/a/635024/935136

sudo date -s "$(curl -s --head http://google.com | grep ^Date: | sed 's/Date: //g')"
sudo dpkg-reconfigure tzdata
Thomas Devoogdt
  • 816
  • 11
  • 16
  • Been driving me crazy for hours -- thanks for that. The PI time was off by 10-days for me causing (it would appear) all kinds of errors during pip install. – SteveJ Oct 24 '18 at 00:32
14

I recently ran into this problem because of my company's web content filter that uses its own Certificate Authority so that it can filter SSL traffic. PIP doesn't seem to be using the system's CA certificates in my case, producing the error you mention. Downgrading PIP to version 1.2.1 presented its own set of problems later on, so I went back to the original version that came with Python 3.4.

My workaround is quite simple: use easy_install. Either it doesn't check the certs (like the old PIP version), or it knows to use the system certs because it works every time for me and I can still use PIP to uninstall packages installed with easy_install.

If that doesn't work and you can get access to a network or computer that doesn't have the issue, you could always setup your own personal PyPI server: how to create local own pypi repository index without mirror?

I almost did that until I tried using easy_install as a last ditch effort.

Community
  • 1
  • 1
Ross Peoples
  • 903
  • 2
  • 13
  • 20
14

TLDR:

pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org -r requirements.txt -vvv

pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org <packageName> -vvv

So, Having 30+ answers to the question already, but nothing was working for me in June 2020 (while in lockdown ).
all were given in different moments of past. I will try to make this answer work for all times in future. The problem is while pip installs package it tries to connect with host URL where package is stored and doesn't trust the URL while downloading it.

There are two ways we can solve this: Easy and non-secure: 1. check which URL is hit by pip to download the package.

pip install <packageName> -vvv

if you will carefully check the output, you will see it might be going to some URL like pypi.org or may be pypi.python.org.

if it is, just add trusted host option to the command like below:

pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org <packageName> -vvv

or if you are using requirements file:

pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org -r requirements.txt -vvv

Secure way:

Go to each of these URL and download their public cert (just google how to download), create a chain, store it as .pem file and run below command:

pip --cert YourPemFile.pem install <packageName>
Nitesh chauhan
  • 316
  • 2
  • 5
13

You can try to bypass the SSL error by using http instead of https. Of course this is not optimal in terms of security, but if you are in a hurry it should do the trick:

pip install --index-url=http://pypi.python.org/simple/ linkchecker
Augusto Destrero
  • 4,095
  • 1
  • 23
  • 25
  • 1
    I was expecting your suggestion to work. Crazily I got the exact same errors including the first one `Could not fetch URL http://pypi.python.org/simple/linkchecker/: connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)` – Jeremy Cook Oct 03 '14 at 15:00
  • Looks like a strange network issue. Can you access https://pypi.python.org from your browser? – Augusto Destrero Oct 03 '14 at 15:23
  • Yes, quite strange. I can access it from my browser, no problem. – Jeremy Cook Oct 03 '14 at 15:28
  • 3
    Ok, so another workaround is downloading the tar.gz package available here https://pypi.python.org/pypi/LinkChecker/9.3 and the installing it with: pip install LinkChecker-9.3.tar.gz – Augusto Destrero Oct 03 '14 at 15:35
  • 3
    But if the package you want to install has dependencies you have to download and install also all dependencies, if they are many this could become a nightmare. – Augusto Destrero Oct 03 '14 at 15:37
  • That's a great suggestion, although I suspect linkchecker has more dependencies then I want to deal with at-the-moment. Based on your feedback and encouragement that this is totally weird I talked to IT and discovered that all SSL traffic is being decrypted/re-encrypted by our firewall. Most likely that is causing the hiccup. I'm going to meet with our firewall guy next week to work out a solution. I'll post back if I discover anything that might be useful to others. – Jeremy Cook Oct 03 '14 at 15:51
  • @JeremyCook The top answer has the appropriate workaround for your firewall. For errors inside python, supplying the certificate chain that trusts your company's firewall to your program is probably the best option. – dragon788 Jul 11 '16 at 14:57
  • 1
    For me, i had to download the whl (for my case pyserial) and install it. This picked up the dependencies that were not collected by the tar.gz... So, maybe whl is another option along the lines of @baxeico python -m pip install pyserial-3.4-py2.py3-none-any.whl For me none of this worked: 1. --cert cacert.pem 2. exporting company certificate, converting to PEM 3. easy_install in cygwin 4. --trusted-host – charo Jan 08 '19 at 20:04
  • 2
    The now longs works as of 2017 -- HTTP access has been completely cut off. https://mail.python.org/pipermail/distutils-sig/2017-October/031712.html – gbtimmon Jan 25 '19 at 21:21
  • pip versions in http://pypi.python.org/simple/ are different than in https://pypi.org, so you cannot upgrade to new versions, e.g. `python -m pip install --upgrade pip --index-url=http://pypi.python.org/simple/ --trusted-host pypi.python.org` – rayzinnz Jan 28 '20 at 00:34
11

You have 4 options:

Using a certificate as parameter

$ pip install --cert /path/to/mycertificate.crt linkchecker

Using a certificate in a pip.conf

Create this file:

$HOME/.pip/pip.conf (Linux)

%HOME%\pip\pip.ini (Windows)

and add these lines:

[global]
cert = /path/to/mycertificate.crt

Ignoring certificate and using HTTP

$ pip install --trusted-host pypi.python.org linkchecker

Ignoring certificate and using HTTP in a pip.conf

Create this file:

$HOME/.pip/pip.conf (Linux)

%HOME%\pip\pip.ini (Windows)

and add these lines:

[global]
trusted-host = pypi.python.org

Source

slm
  • 15,396
  • 12
  • 109
  • 124
Thiago Falcao
  • 4,463
  • 39
  • 34
11

The answers to use

pip install --trusted-host pypi.python.org <package>

work. But you'll have to check if there are redirects or caches pip is hitting. On Windows 7 with pip 9.0.1, I had to run

pip install \
  --trusted-host pypi.python.org \
  --trusted-host pypi.org \
  --trusted-host files.pythonhosted.org \
  <package>

You can find these with the verbose flag.

pmbotter
  • 493
  • 1
  • 6
  • 7
10

I installed pip 1.2.1 with easy_install and upgraded to latest version of pip (6.0.7 at the time) which is able to install packages in my case.

easy_install pip==1.2.1
pip install --upgrade pip
theofanis
  • 119
  • 1
  • 3
9

First of all,

    pip install --trusted-host pypi.python.org <package name>

did not work for me. I kept getting the CERTIFICATE_VERIFY_FAILED error. However, I noticed in the error messages that they referenced the 'pypi.org' site. So, I used this as the trusted host name instead of pypi.python.org. That almost got me there; the load was still failing with CERTIFICATE_VERIFY_FAILED, but at a later point. Finding the reference to the website that was failing, I included it as a trusted host. What eventually worked for me was:

    pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package name>
Pat B.
  • 419
  • 3
  • 12
  • Only your answer worked for me. Any idea how to specify the trusted host configuration in VS Code? – FMFF Sep 07 '20 at 04:34
9

Don't Skip! Found Safe Solution for Linux

All the solutions of adding pypi.org to trusted sites with --trusted-host is not safe, basically skipping https, not really fixing the problem.
Everyone which uses this approach, please try to update your cert this way and remove --trusted-host flag:

sudo yum -y update ca-certificates
export PIP_CERT=/etc/ssl/certs/ca-bundle.crt 

Safety Matters!

Ofek Hod
  • 3,544
  • 2
  • 15
  • 26
8

For Python 3.10

Add/update file with content

[global]
trusted-host = pypi.python.org
           pypi.org
           files.pythonhosted.org

file location

  1. MacOS - $HOME/Library/Application Support/pip/pip.conf

  2. Unix - $HOME/.config/pip/pip.conf

  3. Windows - %APPDATA%\pip\pip.ini

Aniket Singh
  • 2,464
  • 1
  • 21
  • 32
7

I attempted with using the corporate proxy but it failed.

I'm using Python 3.6.

pip.conf file was missing.

Here are the steps to solve the issue:

  1. Install certificate package: -pip --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org install certifi

  2. Create a pip.conf file, as so:

     $ cd ~/.config 
     $ mkdir pip
     $ cd pip
     $ nano pip.conf

Add the following to the newly created .conf file, and save it.

[global]
trusted-host = pypi.python.org files.pythonhosted.org pypi.org pypi.io

All done and it started working.

Ian
  • 3,605
  • 4
  • 31
  • 66
Shabir
  • 107
  • 1
  • 7
  • 1
    I had to figure out a few things to do this on Win10 but this answer got me to the solution when none of the others could. Thanks a ton! – raddevus Sep 20 '21 at 20:34
6

Had the same problem trying pip install ftputil with ActivePython 2.7.8, ActivePython 3.4.1, and "stock" Python 3.4.2 on 64-bit Windows 7 Enterprise. All attempts failed with the same errors as OP.

Worked around the problem for Python 3.4.2 by downgrading to pip 1.2.1: easy_install pip==1.2.1 (see https://stackoverflow.com/a/16370731/234235). Same fix also worked for ActivePython 2.7.8.

The bug, reported in March 2013, is still open: https://github.com/pypa/pip/issues/829.

Community
  • 1
  • 1
psteiner
  • 187
  • 3
  • 17
  • This worked for me as well. While it might seem like a bad idea in the first place to downgrade to an older version of pip, I was dealing with old django packages so the old pip version was actually matching with the other packages. – mknaf Jun 02 '15 at 15:20
  • Issue 829 is now closed. – Ortomala Lokni Dec 15 '15 at 13:48
6

I'm not sure if this is related, but I had a similar problem which was fixed by copying these files from Anaconda3/Library/bin to Anaconda3/DLLs :

libcrypto-1_1-x64.dll

libssl-1_1-x64.dll

ColdCold
  • 4,181
  • 2
  • 26
  • 20
  • With Anaconda 2019.03 I have copied the following files from /Library/bin to /DLLs libcrypto-1_1-x64.dll libcrypto-1_1-x64.pdb libssh2.dll libssl-1_1-x64.dll libssl-1_1-x64.pdb Then I add a ConnectTimeout error, so updated proxy configuration .condarc – MordicusEtCubitus Jul 15 '19 at 12:38
  • Works. Man you're GENIUS! I've been roaming the forums for 1.5 hour, just to find this underestimated and simple solution. – ivan866 Mar 06 '20 at 14:46
5

One solution (for Windows) is to create a file called pip.ini on the %AppData%\pip\ folder (create the folder if it doesn't exist) and insert the following details:

[global]
cert = C:/certs/python_root.pem
proxy = http://my_user@my_company.com:my_password@proxy_ip:proxy_port

...and then we can execute the install instruction:

pip3 install PyQt5

Another option is to install the package using arguments for the proxy and certificate...

$ pip3 install --proxy http://my_user@my_company.com:my_password@proxy_ip:proxy_port \
   --cert C:/certs/python_root.pem PyQt5

To convert the certificate *.cer files to the required *.pem format execute the following instruction:

$ openssl x509 -inform der -in python_root.cer -out python_root.pem

Hope this helps someone!

slm
  • 15,396
  • 12
  • 109
  • 124
Marco
  • 2,445
  • 2
  • 25
  • 15
5

Nothing on this page worked for me until I used the --verbose option to see that it wanted to get to files.pythonhosted.org rather than pypi.python.org:

pip install --trusted-host files.pythonhosted.org <package_name>

So check the URL that it's actually failing on via the --verbose option.

Dan Austin
  • 79
  • 1
  • 4
5

Short Solution:

easy_install <package name>

For Example:

easy_install pandas

Alternate solution:

pip install <package_name> --trusted-host pypi.org --trusted-host files.pythonhosted.org

Example:

pip install pandas --trusted-host pypi.org --trusted-host files.pythonhosted.org
Gil Baggio
  • 13,019
  • 3
  • 48
  • 37
4

Recently I faced the same issue in python 3.6 with visual studio 2015. After spending 2 days, I got the solution and its working fine for me.

I got below error while try to install numpy using pip or from visual studio Collecting numpy Could not fetch URL https://pypi.python.org/simple/numpy/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748) - skipping Could not find a version that satisfies the requirement numpy (from versions: ) No matching distribution found for numpy

Resolution :

For Windows OS

  1. open -> "%appdata%" Create "pip" folder if not exists.
  2. In pip folder create "pip.ini" file.
  3. Edit file and write
    [global]
    trusted-host = pypi.python.org Save and Close the file. Now install using pip/visual studio it works fine.
4

In my case it was due to SSL certificate being signed by internal CA of my company. Using workarounds like pip --cert did not help, but the following package did:

pip install pip_system_certs

See: https://pypi.org/project/pip-system-certs/

This package patches pip and requests at runtime to use certificates from the default system store (rather than the bundled certs ca).

This will allow pip to verify tls/ssl connections to servers who’s cert is trusted by your system install.

Community
  • 1
  • 1
0x416e746f6e
  • 9,872
  • 5
  • 40
  • 68
  • 4
    it seems need to install pip_sysem_certs to void the [SSL: CERTIFICATE_VERIFY_FAILED] error, the problem is, trying to install it got the [SSL: CERTIFICATE_VERIFY_FAILED] error... – athos Jun 17 '19 at 08:26
  • This may have been a solution at some point in time, but `pip_system_certs` completely broke my Python environment, and for that reason this is not a good answer. Do not install pip_system_certs. See https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error for more information. – h0r53 Jan 14 '20 at 22:09
  • Set the proxy on your server and then run: 'C:\Windows\system32>curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py --proxy proxyx:80' – Patrick Burwell Sep 10 '21 at 15:46
  • This also worked for me and my work machine, I have not encountered any issues – RedKlouds Feb 08 '23 at 17:45
  • @athos pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org pip pip_system_certs – RedKlouds Feb 08 '23 at 17:46
4

Just putting this here as I don't see any other mentioning it.

You can set globally trusted-host to pip like this:

py -m pip config set global.trusted-host pypi.org

and most importantly, it will return the right place where the pip.ini/pip.conf is put

LionH
  • 194
  • 6
3

I solved this problem by removing my pip and installing the older version of pip: https://pypi.python.org/pypi/pip/1.2.1

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/13460881) – apomene Aug 26 '16 at 07:57
  • @apomene how is OP supposed to `include the essential parts of the answer here` since it's a link to a *binary file*...? – Thomas Ayoub Aug 26 '16 at 09:33
  • @ThomasAyoub, i believe you already know, that the above message is auto filled from SO, when flagging an answer as only link answer – apomene Aug 26 '16 at 09:41
  • @apomene that doesn't answer my question, I still don't see what OP could/should add? – Thomas Ayoub Aug 26 '16 at 09:44
  • 1
    @ThomasAyoub, To elaborate further, my comment (SO) indicates that question is short and link only, meaning it could better be a comment. My intention was not to explicitly state that OP should add details regrading the link, but details on why this answers the question. – apomene Aug 26 '16 at 09:49
2

You can try this to ignore "https":

pip install --index-url=http://pypi.python.org/simple/ --trusted-host pypi.python.org  [your package..]
Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
Smaillns
  • 2,540
  • 1
  • 28
  • 40
  • 1
    if you even have other problems with pip version you can try this `pip install --trusted-host pypi.python.org --upgrade pip –` – Smaillns Aug 09 '17 at 04:53
2

I faced a similar issue. The solution that worked for me 1) uninstall python 2.7 2) delete python27 folder 3) reinstall the latest python

Satyam Raikar
  • 465
  • 6
  • 20
2

If you are using Anaconda and facing this issue only when running pip within an environment, you might need to reinstall python.

Run conda install python within the desired environment.

Danish Shakeel
  • 258
  • 3
  • 12
2

running pip install certifi before installing any other package solved my problem

Ibnu Sina
  • 59
  • 2
2

Despite there being >40 answers, AFAIK none of them completely solved the issue for me.

I'm on macOS Catalina 10.15.5, behind a corporate proxy.

When attempting to install or upgrade a package, I was given the following error

>>> pip install <package name>                                                                                                                           

Looking in indexes: https://pypi.org/simple, https://data:****@pypi.<company>.com/simple/
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: unable to get local issuer certificate (_ssl.c:1108)'))': <package name>
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: unable to get local issuer certificate (_ssl.c:1108)'))': <package name>

@Steve_Tauber's answer pip --cert /etc/ssl/certs/FOO_Root_CA.pem install linkchecker got me part of the way there.

I was able to use the existing cert file to successfully install packages, as so:

pip install --cert /Users/me/opt/anaconda3/ssl/cert.pem --upgrade pip

But I didn't want to have to use the cert flag every time I wanted to use pip...

The answer is to update environment variables:

CERT_PATH=/Users/me/opt/anaconda3/ssl/cert.pem
export SSL_CERT_FILE=${CERT_PATH}
export REQUESTS_CA_BUNDLE=${CERT_PATH}

And now I can install without issues.

Ian
  • 3,605
  • 4
  • 31
  • 66
2

If nothing help you and you on MacOS. Just look at python folder and run Install Certificates.command Only this help me.

enter image description here

S__
  • 404
  • 5
  • 13
1

for me this is because previously I'm running script which set proxy (to fiddler), reopening console or reboot fix the problem.

uingtea
  • 6,002
  • 2
  • 26
  • 40
  • Fiddler can be bypassed by setting "Decrypt HTTPS traffic" to "...from browsers only" in Tools|Options. This fixed the issue for me. – tephyr Jul 10 '17 at 22:58
1

In my case, I was running Python in the minimal alpine docker image. It was missing root CA certificates. Fix:

apk update && apk add ca-certificates

Martin Melka
  • 7,177
  • 16
  • 79
  • 138
1

As of now when pip has upgraded to 10 and now they have changed their path from pypi.python.org to files.pythonhosted.org Please update the command to pip --trusted-host files.pythonhosted.org install python_package

Shivam Kotwalia
  • 1,419
  • 2
  • 15
  • 20
1

Vaulstein answer helped me.

I did not find the pip.ini file anywhere on my pc. So did the following.

  1. Went to the the AppData folder. You can get the appdata folder by opening up the command prompt and type echo %AppData%

AppData location using command prompt

Or simply type %AppData% in windows explorer.

AppData location in windows explorer

  1. Create a folder called pip inside of that appdata folder.

  2. In that pip folder that you just created, create a simple textfile called pip.ini

  3. Past the following config settings in that file using a simple editor of your choice.

pip.ini file:

[list]
format=columns

[global]
trusted-host = pypi.python.org pypi.org

You should now be good to go.

Johann Burgess
  • 580
  • 6
  • 17
VivekDev
  • 20,868
  • 27
  • 132
  • 202
1

Alternatively, if nothing works (as was my case) you can revert to searching and downloading a whl file here:

https://pypi.org/project/fileDownloader.py/

Before installing it via pip using the downloaded file which won't require any certificate anymore:

python3.7 -m pip install Myfile.whl
breizhmg
  • 1,081
  • 8
  • 7
1

I have this problem with pip 21.0.1 and none of the answers worked for me. Some people solved the problem by downgrading the pip version.

If in 2021 you still have this problem, I did downgrade to pip 20.2.4 and now it works.

Soheila Hg
  • 569
  • 2
  • 7
  • 25
1

I was getting the same error even after trying many hacks. So I went to the official site(https://pypi.org/project/) where we can find wheel files(.whl) of particular package and downloaded that.

Now in command prompt:

pip install path_to_wheel_file/file_name.whl

Now the file is installed succesfully.

0

For me none of the suggested methods worked - using cert, HTTP, trusted-host.

In my case switching to a different version of the package worked (paho-mqtt 1.3.1 instead of paho-mqtt 1.3.0 in this instance).

Looks like problem was specific to that package version.

MiN
  • 175
  • 1
  • 12
0

You may have this problem if some certificates are missing in your system.eg on opensuse install ca-certificates-mozilla

sancelot
  • 1,905
  • 12
  • 31
0

Short answer

If running into this at home on a corporate machine, try again at work.

Details

I ran into this over the weekend. Pip and conda both broken, unable to install or update. SO was helpful, but many answers were problematic on a corporate machine - the solutions require the ability to pip install (already does not work) or require downloading an installer (the ones I wanted to download were prohibited by firewall settings).

What worked for me was to try again when I was on prem. This worked. It turned out the corporate firewall settings were different when using the machine at home vs at work.

Bill Needels
  • 505
  • 4
  • 13
0

This is what worked for me:

$ sudo mv /etc/ssl/cert.pem /etc/ssl/cert.pem.BAK

In my situation, I was getting the same error for pip installs and a similar one when trying to run aws CLI commands. Everything was working one week, then not the next. AFAIK, I didn't install anything that would have broken SSL.

I'm on MacOS Big Sur and tried various versions of Python 3.x, installed via both pyenv and Brew. I tried all of the relevant solutions listed in this thread. I even re-installed the OS, but no dice.

MacGruber
  • 861
  • 1
  • 7
  • 8
0

I tried every thing in this list! none did the trick. I realize my connection wasn't steady- so I plug the power of my modem for 1 minute solved my problem :)

Adi Shumely
  • 367
  • 3
  • 5
0

Set your proxy in connections and then run:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py --proxy proxy:80
Patrick Burwell
  • 129
  • 1
  • 12
0

fixed my issue on OSX by running the following in the terminal:

open "/Applications/Python 3.9/Install Certificates.command"
Itay Bianco
  • 697
  • 6
  • 16
0

If you have compiles the Python, then do the following thing to get SSL enabled in the Python.

wget --no-check-certificate https://www.python.org/ftp/python/3.9.10/Python-3.9.10.tgz
tar -zxf Python-3.9.10.tgz
cd Python-3.9.10
mkdir /home/$USER/tools
export INSTALL_BASE_PATH=/home/$USER/tools

mkdir -p {INSTALL_BASE_PATH}/ssl
vi ./Modules/Setup      # Modify below lines in this file to these
SSL={INSTALL_BASE_PATH}/ssl
_ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib -lssl -lcrypto
./configure \
    --prefix=${INSTALL_BASE_PATH} \
    --enable-shared \
    --enable-ipv6 \
    LDFLAGS=-Wl,-rpath=${INSTALL_BASE_PATH}/lib,--disable-new-dtags

make
make install
Shashi Ranjan
  • 353
  • 2
  • 8
0

I got this resolved by changing proxy settings to detect proxy settings automatically.

Screenshot

0

If the other suggestions are not working for you, the fix that worked for me was:

  1. use pyenv to install a new python version
  2. switch to the new python version
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Gokul Kurup
  • 91
  • 2
  • 9
0

You can expand pip install to pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org automatically via shell function

Append following lines in your ~/.bashrc for a permanent fix

function pip {
  case $@ in
    install* ) shift 1; command pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org "$@" ;;
    * ) command pip "$@" ;;
  esac
}

See following gist for easy installation of the fix
https://gist.github.com/WingTillDie/d38c16a150193d2e30807bf62c78118a

-1

If you've installed Python manually using make you will have to follow this answer: https://stackoverflow.com/a/42798679/6403406 to get it working.

waqasgard
  • 801
  • 7
  • 25
-2

if you are using a virtual environment I would recommend using this solution,

pyenv install (wanted_python_version)

  • it worked for me with a new virtualenv after that command and reinstalling the frozen packages from the old one (Os MacOs catalina 10.15.1) – Houssem Gharbi Dec 28 '19 at 21:06