1. 程式人生 > 實用技巧 >SSL certificate verify failed” using pip to install packages

SSL certificate verify failed” using pip to install packages

https://stackoverflow.com/questions/42509902/ssl-certificate-verify-failed-using-pip-to-install-packages/49910594 https://stackoverflow.com/questions/25981703/pip-install-fails-with-connection-error-ssl-certificate-verify-failed-certi Asked3 years, 4 months ago Active1 month ago Viewed80k times 13

I am trying to install the Scrapy package (among others) for python using pip. I have tried doing the installation using python 3 and python 2, I have installed/upgraded the setuptools like so:$ pip3 install --upgrade setuptools

, I have tried to use the--trusted-hostoption like so:$ pip3 install --trusted-host pypi.python.org Scrapy. But I always get the same error message when I run$ pip3 install Scrapy. The complete output is this:

Collecting Scrapy
  Using cached Scrapy-1.3.2-py2.py3-none-any.whl
Collecting PyDispatcher>=2.0.5 (from Scrapy)
  Using cached PyDispatcher-2.0.5.tar.gz
Collecting service-identity (from Scrapy)
  Using cached service_identity-16.0.0-py2.py3-none-any.whl
Collecting pyOpenSSL (from Scrapy)
  Using cached pyOpenSSL-16.2.0-py2.py3-none-any.whl
Collecting w3lib>=1.15.0 (from Scrapy)
  Using cached w3lib-1.17.0-py2.py3-none-any.whl
Collecting parsel>=1.1 (from Scrapy)
  Using cached parsel-1.1.0-py2.py3-none-any.whl
Collecting queuelib (from Scrapy)
  Using cached queuelib-1.4.2-py2.py3-none-any.whl
Requirement already satisfied: six>=1.5.2 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from Scrapy)
Collecting Twisted>=13.1.0 (from Scrapy)
  Using cached Twisted-17.1.0.tar.bz2
    Complete output from command python setup.py egg_info:
    Download error on https://pypi.python.org/simple/incremental/: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) -- Some packages may not be found!
    Couldn't find index page for 'incremental' (maybe misspelled?)
    Download error on https://pypi.python.org/simple/: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) -- Some packages may not be found!
    No local packages or working download links found for incremental>=16.10.1
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/gy/5xt04_452z791v1qjs1yzxkh0000gn/T/pip-build-nkv4jozy/Twisted/setup.py", line 21, in <module>
        setuptools.setup(**_setup["getSetupArgs"]())
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/dist.py", line 317, in __init__
        self.fetch_build_eggs(attrs['setup_requires'])
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/dist.py", line 372, in fetch_build_eggs
        replace_conflicting=True,
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 851, in resolve
        dist = best[req.key] = env.best_match(req, ws, installer)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1123, in best_match
        return self.obtain(req, installer)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1135, in obtain
        return installer(requirement)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/dist.py", line 440, in fetch_build_egg
        return cmd.easy_install(req)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 668, in easy_install
        raise DistutilsError(msg)
    distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('incremental>=16.10.1')

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/gy/5xt04_452z791v1qjs1yzxkh0000gn/T/pip-build-nkv4jozy/Twisted/

I am on a mac OS version 10.12.1 and am using python 3.6. Does anybody know a solution to this problem?

shareimprove this question askedFeb 28 '17 at 13:21 imc 62622 gold badges66 silver badges2020 bronze badges add a comment

13 Answers

ActiveOldestVotes 13

pip install --trusted-host pypi.python.org autopep8 (any package name)

This command will addpypi.python.orgto the trusted sources and will install all the required package.

I ran into the error myself and typing this command helped me install all the pip packages of python.

shareimprove this answer editedJul 16 '17 at 7:49 EsmaeelE 1,58333 gold badges1414 silver badges2222 bronze badges answeredJul 16 '17 at 0:00 Teja Swaroop 16711 silver badge66 bronze badges
  • 3 it should be noted that this is a VERY RISKY IDEA! this disables HTTPS certificate validation, and allows a man in the middle to install ARBITRARY CODE. curl calls this option --insecure (which is more accurate than "trusted"). the accepted answer about OpenSSL is correct–Ricky CookJan 21 '19 at 0:07
add a comment 10

As stated herehttps://bugs.python.org/issue28150in previous versions of python Apple supplied the OpenSSL packages but does not anymore.

Running the commandpip install certifiand thenpip install Scrapyfixed it for me

shareimprove this answer answeredFeb 28 '17 at 15:03 imc 62622 gold badges66 silver badges2020 bronze badges
  • also possible to install OpenSSL via brew (or whatever package manager). on some Linux systems, you also may need to install ca-certificates (or whatever variation of that your distro has, but that's usually the correct name)–Ricky CookJan 21 '19 at 0:10
add a comment 8

One note on the above answers: it is no longer sufficient to add just pypi.python.org to the trusted-hosts in the case where you are behind an HTTPS-intercepting proxy (we have zScaler).

I currently have the following in my pip.ini:

trusted-host = pypi.python.org pypi.org files.pythonhosted.org

Runningpip -v install pkgwill give you some hints as to which hosts might need to be added.

shareimprove this answer answeredApr 18 '18 at 23:42 Greg 20522 silver badges66 bronze badges
  • If pip.ini does not exist, you have to also create the [global] section, then put in the "trusted-host = ..." line.–Pieter-Jan BusschaertAug 27 '18 at 14:24
  • You can also supply multiple--trusted-hostarguments to yourpip install.–dragon788Nov 21 '18 at 16:03
  • 2 it should be noted that this is a VERY RISKY IDEA! this disables HTTPS certificate validation, and allows a man in the middle to install ARBITRARY CODE. curl calls this option --insecure (which is more accurate than "trusted"). the accepted answer about OpenSSL is correct–Ricky CookJan 21 '19 at 0:08
add a comment 4

Something to try --- tell python to not use https with the index directive and a http:// address (not https://)

pip install --index-url=http://pypi.python.org/simple/ --trusted-host pypi.python.org  Scrapy

You may be behind a corporate firewall and Ive have experiences where even the above failed, though Im not going to pretend like I know enough about firewalls or SSL to understand why. In that case the only way I was able to get around that was to get a certificate file and pass it to python. Seekenorb’s answerhere for details.

shareimprove this answer editedMay 23 '17 at 11:47 Community 111 silver badge answeredFeb 28 '17 at 14:02 gbtimmon 3,74811 gold badge1616 silver badges3030 bronze badges add a comment 2

It seems thatScrapyfails because installingTwistedfails, which fails becauseincrementalfails. Runningpip install --upgrade pip && pip install --upgrade incrementalfixed this for me.

shareimprove this answer answeredJan 17 '19 at 1:36 cowlinator 3,36044 gold badges1717 silver badges3434 bronze badges add a comment 1

If adding pypi.python.org as a trusted host does not work, you try adding files.pythonhosted.org. For example

python -m pip install --upgrade --trusted-host files.pythonhosted.org <package-name>
shareimprove this answer answeredApr 18 '18 at 16:37 user2055509 2911 bronze badge add a comment 1

It looks like they are also using pypi.org now. I added the following to %appdata%\pip\pip.ini and was able to download my packages from behind an HTTPS-intercepting proxy:

trusted-host = pypi.python.org files.pythonhosted.org pypi.org

shareimprove this answer answeredJul 25 '18 at 19:10 Chris Lope 8366 bronze badges add a comment 1

In Windows 10 / search the drive you have installed the conda or it should be in C:\Users\name\AppData\Roaming\pipright with your mouse right click and select edit with notepad leave the [global] and replace what ever you have in there with blow code, Ctrl+s and rerun the code. it should work.

trusted-host = pypi.python.org pypi.org files.pythonhosted.org
shareimprove this answer answeredJun 23 '19 at 21:49 Reza Hashemi 1111 silver badge33 bronze badges add a comment 1
 pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org <app>
shareimprove this answer editedAug 9 '19 at 8:57 Shree 17.8k2222 gold badges8383 silver badges129129 bronze badges answeredAug 9 '19 at 8:55 rtl 1111 bronze badge add a comment 0

You can trysudo apt-get upgradeto get the latest packages. It fixed the issue on my machine.

shareimprove this answer answeredApr 26 '18 at 20:48 marw 2,07933 gold badges2323 silver badges3434 bronze badges add a comment 0

If you're using python3, you can try this too:

python3 -m pip install --upgrade Scrapy --trusted-host pypi.org --trusted-host files.pythonhosted.org
shareimprove this answer editedJan 1 '19 at 22:30 LundinCast 6,68444 gold badges2222 silver badges3636 bronze badges answeredJan 1 '19 at 12:33 Hakim Asa 32911 silver badge1111 bronze badges add a comment 0

I had same issue. I was trying to installmysqlclientfor my Django project.

In my case thesystem date/timewasn't up-to date (Windows 8). That's causing the error. So, updated my system date time and ran the commandpip install mysqlclientagain. And it did the work.

Hope this would be helpful for those people who're executing all the commands out there (suggesting in other answers) without checking their system date/time.

shareimprove this answer answeredJul 26 '19 at 7:01 Shashanth 3,69166 gold badges2929 silver badges4343 bronze badges add a comment 0

Thank you for the solution. In my case the file %appdata%\pip\pip.ini was not present. I created it manually with this content:

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