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

使用pip install PySQL时遭遇subprocess-exited-with-error错误求助

安装PySQL时遇到SyntaxError:multiple exception types must be parenthesized

问题重现

执行pip install PySQL命令时触发编译错误,核心报错为:

SyntaxError: multiple exception types must be parenthesized

完整错误日志:

C. Administrator: Command Prompt
Microsoft Windows [Version 10.0.19045.4598] (c) Microsoft Corporation. All rights reserved.
C:\WINDOWS\system32>pip install PySQL Collecting PySQL
Using cached pysql-0.16.tar.gz (127 kB) Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error
* Getting requirements to build wheel did not run successfully.
exit code: 1
[22 lines of output]
Traceback (most recent call last):
File "C:\Users\bhart\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module> main() File "C:\Users\bhart\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
json_out['return_val'] = hook (**hook_input['kwargs'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\bhart\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel return hook(config_settings)
ΑΛΛΑ
File "C:\Users\bhart\AppData\Local\Temp\pip-build-env-snahbmx_\overlay\Lib\site-packages\setuptools\build_meta.py", line 327, in get_requires_for_build_wheel return self._get_build_requires (config_settings, requirements=[])
ΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑΛΑ
File "C:\Users\bhart\AppData\Local\Temp\pip-build-env-snahbmx_\overlay\Lib\site-packages\setuptools\build_meta.py", line 297, in _get_build_requires
self.run_setup()
File "C:\Users\bhart\AppData\Local\Temp\pip-build-env-snahbmx_\overlay\Lib\site-packages\setuptools\build_meta.py", line 497, in run_setup
super().run_setup(setup_script_setup_script)
File "C:\Users\bhart\AppData\Local\Temp\pip-build-env-snahbmx_\overlay\Lib\site-packages\setuptools\build_meta.py", line 313, in run_setup exec(code, locals())
File "<string>", line 31
except Exception, e:
^^^^^^^^^^^^
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: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
exit code: 1
> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.

错误原因

你使用的是Python 3.12,但PySQL 0.16版本的代码采用了Python 2的异常捕获语法except Exception, e:,这种写法在Python 3中已被废弃,必须改为except Exception as e:才能被识别。修改本地setup.py无效,因为问题出在下载的PySQL源码包内部代码中。

解决方案

1. 改用维护中的MySQL Python驱动(推荐)

PySQL属于停止更新的旧包,建议使用官方或主流的MySQL驱动:

  • 安装官方驱动:pip install mysql-connector-python
  • 安装PyMySQL:pip install pymysql
    这两个包均支持Python 3.12,且持续维护。

2. 修改PySQL源码后本地安装

若必须使用PySQL,需手动修改源码中的Python 2语法:

  1. 下载缓存的pysql-0.16.tar.gz并解压
  2. 遍历解压目录下所有.py文件,将所有except [异常类型], e:格式的代码替换为except [异常类型] as e:
  3. 进入解压后的目录,执行pip install .完成本地安装

3. 降级Python版本(不推荐)

可降级到Python 2.7兼容旧语法,但Python 2已停止官方维护,存在安全风险,不建议采用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 10:34:52