You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装ssl模块遇subprocess-exited-with-error等错误求助

问题:Python 3.11.5 执行pip install ssl报错SyntaxError: multiple exception types must be parenthesized

环境:Windows 10 x64系统,Python 3.11.5(最新稳定版)、Wheel 0.41.2、Setuptools 68.1.2
执行pip install ssl时遭遇subprocess-exited-with-error错误,python setup.py egg_info执行失败,具体报错为语法错误SyntaxError: multiple exception types must be parenthesized。已尝试升级Python、Wheel和Setuptools,问题未解决,寻求安装ssl模块的有效方案。

完整报错信息:

C:\WINDOWS\system32>pip install ssl
Collecting ssl
  Using cached ssl-1.16.tar.gz (33 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [28 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 14, in <module>
        File "C:\Users\WINDOWS\AppData\Local\Programs\Python\Python311\Lib\site-packages\setuptools\__init__.py", line 270, in <module>
          monkey.patch_all()
        File "C:\Users\WINDOWS\AppData\Local\Programs\Python\Python311\Lib\site-packages\setuptools\monkey.py", line 96, in patch_all
          patch_for_msvc_specialized_compiler()
        File "C:\Users\WINDOWS\AppData\Local\Programs\Python\Python311\Lib\site-packages\setuptools\monkey.py", line 156, in patch_for_msvc_specialized_compiler
          patch_func(*msvc14('_get_vc_env'))
                      ^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\WINDOWS\AppData\Local\Programs\Python\Python311\Lib\site-packages\setuptools\monkey.py", line 146, in patch_params
          mod = import_module(mod_name)
                ^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\WINDOWS\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module
          return _bootstrap._gcd_import(name[level:], package, level)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\WINDOWS\AppData\Local\Programs\Python\Python311\Lib\site-packages\setuptools\_distutils\_msvccompiler.py", line 20, in <module>
          import unittest.mock as mock
        File "C:\Users\WINDOWS\AppData\Local\Programs\Python\Python311\Lib\unittest\mock.py", line 26, in <module>
          import asyncio
        File "C:\Users\WINDOWS\AppData\Local\Programs\Python\Python311\Lib\asyncio\__init__.py", line 8, in <module>
          from .base_events import *
        File "C:\Users\WINDOWS\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 34, in <module>
          import ssl
        File "C:\Users\WINDOWS\AppData\Local\Temp\pip-install-6t66qbb1\ssl_2992740d127c414fa526766aa7d3f686\ssl\__init__.py", line 140
          except SSLError, x:
                 ^^^^^^^^^^^
      SyntaxError: multiple exception types must be parenthesized
      [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.

报错原因分析

  • 你尝试安装的ssl是PyPI上的老旧第三方包(版本1.16),代码采用Python 2的异常捕获语法(except SSLError, x:),而Python 3.11仅支持Python 3的语法(except SSLError as x:),直接触发语法错误。
  • 核心要点:Python从2.7版本开始,标准库已内置ssl模块,完全不需要通过pip安装。

有效解决方案

1. 直接使用内置ssl模块

无需额外安装,代码中直接导入即可使用:

import ssl

如果代码提示找不到ssl模块,大概率是Python安装不完整,而非缺少该包。

2. 修复Python安装(若内置模块缺失)

  • 卸载当前Python 3.11.5,重新下载官方Windows x64安装包,安装时勾选Add Python to PATH,确保安装过程无中断。
  • 安装完成后,打开命令行执行以下命令验证:
python -c "import ssl; print(ssl.VERSION)"

能正常输出版本号,说明内置模块功能正常。

3. 卸载错误安装的第三方ssl包

如果已误装该老旧包,执行以下命令卸载:

pip uninstall ssl

内容的提问来源于stack exchange,提问作者Uday Shirbhate

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 05:25:32