如何修复安装Python库时出现的Python SSL证书错误?[duplicate]

o0lyfsai  于 2023-01-01  发布在  Python
关注(0)|答案(1)|浏览(175)
    • 此问题在此处已有答案**:

installing packages with pip returns error [duplicate](1个答案)
Python Requests throwing SSLError(28个答案)
pip install fail with SSL certificate verify failed (_ssl.c:833)(3个答案)
昨天关门了。
此帖子在18小时前编辑并提交审查。
我在Python中安装软件包时遇到了一个问题,几天前才开始,程序运行正常,但每当我尝试运行pip install Pillow或pip install pygame(测试了各种图形库)时,我总是遇到同样的错误。

Collecting pygame
  Using cached pygame-2.1.2.tar.gz (10.1 MB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [70 lines of output]

      WARNING, No "Setup" File Exists, Running "buildconfig/config.py"
      Using WINDOWS configuration...

      Traceback (most recent call last):
        File "C:\msys64\mingw64\lib\python3.9\urllib\request.py", line 1346, in do_open
          h.request(req.get_method(), req.selector, req.data, headers,
        File "C:\msys64\mingw64\lib\python3.9\http\client.py", line 1285, in request
          self._send_request(method, url, body, headers, encode_chunked)
        File "C:\msys64\mingw64\lib\python3.9\http\client.py", line 1331, in _send_request
          self.endheaders(body, encode_chunked=encode_chunked)
        File "C:\msys64\mingw64\lib\python3.9\http\client.py", line 1280, in endheaders
          self._send_output(message_body, encode_chunked=encode_chunked)
        File "C:\msys64\mingw64\lib\python3.9\http\client.py", line 1040, in _send_output
          self.send(msg)
        File "C:\msys64\mingw64\lib\python3.9\http\client.py", line 980, in send
          self.connect()
        File "C:\msys64\mingw64\lib\python3.9\http\client.py", line 1454, in connect
          self.sock = self._context.wrap_socket(self.sock,
        File "C:\msys64\mingw64\lib\python3.9\ssl.py", line 500, in wrap_socket
          return self.sslsocket_class._create(
        File "C:\msys64\mingw64\lib\python3.9\ssl.py", line 1040, in _create
          self.do_handshake()
        File "C:\msys64\mingw64\lib\python3.9\ssl.py", line 1309, in do_handshake
          self._sslobj.do_handshake()
      ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)

      During handling of the above exception, another exception occurred:

      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\ronit\AppData\Local\Temp\pip-install-j1yeb0r5\pygame_2f7b886e356f433a8184f298ab684d13\setup.py", line 359, in <module>
          buildconfig.config.main(AUTO_CONFIG)
        File "C:\Users\ronit\AppData\Local\Temp\pip-install-j1yeb0r5\pygame_2f7b886e356f433a8184f298ab684d13\buildconfig\config.py", line 225, in main
          deps = CFG.main(**kwds)
        File "C:\Users\ronit\AppData\Local\Temp\pip-install-j1yeb0r5\pygame_2f7b886e356f433a8184f298ab684d13\buildconfig\config_win.py", line 497, in main
          and download_win_prebuilt.ask(**download_kwargs):
        File "C:\Users\ronit\AppData\Local\Temp\pip-install-j1yeb0r5\pygame_2f7b886e356f433a8184f298ab684d13\buildconfig\download_win_prebuilt.py", line 290, in ask
          update(x86=x86, x64=x64)
        File "C:\Users\ronit\AppData\Local\Temp\pip-install-j1yeb0r5\pygame_2f7b886e356f433a8184f298ab684d13\buildconfig\download_win_prebuilt.py", line 273, in update
          download_prebuilts(download_dir, x86=x86, x64=x64)
        File "C:\Users\ronit\AppData\Local\Temp\pip-install-j1yeb0r5\pygame_2f7b886e356f433a8184f298ab684d13\buildconfig\download_win_prebuilt.py", line 124, in download_prebuilts
          download_sha1_unzip(url, checksum, temp_dir, 1)
        File "C:\Users\ronit\AppData\Local\Temp\pip-install-j1yeb0r5\pygame_2f7b886e356f433a8184f298ab684d13\buildconfig\download_win_prebuilt.py", line 54, in download_sha1_unzip
          response = urllib.urlopen(request).read()
        File "C:\msys64\mingw64\lib\python3.9\urllib\request.py", line 214, in urlopen
          return opener.open(url, data, timeout)
        File "C:\msys64\mingw64\lib\python3.9\urllib\request.py", line 517, in open
          response = self._open(req, data)
        File "C:\msys64\mingw64\lib\python3.9\urllib\request.py", line 534, in _open
          result = self._call_chain(self.handle_open, protocol, protocol +
        File "C:\msys64\mingw64\lib\python3.9\urllib\request.py", line 494, in _call_chain
          result = func(*args)
        File "C:\msys64\mingw64\lib\python3.9\urllib\request.py", line 1389, in https_open
          return self.do_open(http.client.HTTPSConnection, req,
        File "C:\msys64\mingw64\lib\python3.9\urllib\request.py", line 1349, in do_open
          raise URLError(err)
      urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)>
      Making dir :prebuilt_downloads:
      Downloading... https://www.libsdl.org/release/SDL2-devel-2.0.18-VC.zip ed561079ec622b0bab5a9e02976f5d540b0622da

      ---
      For help with compilation see:
          https://www.pygame.org/wiki/CompileWindows
      To contribute to pygame development see:
          https://www.pygame.org/contribute.html
      ---

      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

我试过升级pip,降级pip,安装新版本的Python,我试过各种各样的install命令来让它工作,尝试升级证书时,错误变成了这个。

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:1129)'))': /simple/pygame/
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:1129)'))': /simple/pygame/
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: unable to get local issuer certificate (_ssl.c:1129)'))': /simple/pygame/
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: unable to get local issuer certificate (_ssl.c:1129)'))': /simple/pygame/
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: unable to get local issuer certificate (_ssl.c:1129)'))': /simple/pygame/
Could not fetch URL https://pypi.org/simple/pygame/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pygame/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)'))) - skipping
ERROR: Could not find a version that satisfies the requirement pygame (from versions: none)
ERROR: No matching distribution found for pygame

我在网上找到的解决方案似乎是面向Mac的,而我运行的是Windows。我不知道问题发生在哪里,因为Python程序运行得很好(我在VSC和PyCharm上都试过了,似乎没有任何问题)。我该如何解决这个问题?

    • 编辑**这个问题可能看起来和其他问题类似,但是我已经尝试了与pip安装相关的解决方案,没有一个有效。关于代理的问题在这个场景中不适用。这个问题与Python代码本身没有任何关系。
    • 编辑2:解决方案**解决了这个问题。不得不卸载几乎所有的东西,从mingw64文件夹中删除Python 3.9和pip,然后使用一个新的非mingw版本的pip-这似乎已经解决了这个问题。不知道为什么会解决这个问题,因为我可以很好地安装tkinter,所以,如果有人能够阐明它,这将是非常有帮助的,因为我不能为我的生活明白出了什么问题.我现在知道,虽然,与编程,卸载/重新安装总是工作.
bvjxkvbb

bvjxkvbb1#

我不知道确切的情况,但你能试试吗

pip install pip-system-certs

相关问题