RHEL8下WSGI环境调用pd.read_sql报AttributeError问题排查
WSGI环境下Pandas 1.1.5报AttributeError: 'module' has no attribute 'read_sql'的排查与根因
问题场景
环境:Python 3.6(RHEL 8)、Pandas 1.1.5
执行代码:
pd.read_sql(<my query>, conn).to_dict(orient="records")
抛出错误:
AttributeError: module 'pandas' has no attribute 'read_sql'
异常特征
- 命令行执行
python3 -c "import pandas; print(str(pandas.__dict__))",可明确看到read_sql函数存在 - 卸载重装Pandas后问题未解决
- 仅在WSGI环境触发错误,非WSGI的测试服务器运行正常
排查结论
对比WSGI环境与测试服务器的Python路径、pandas.__dict__内容后,定位到真实根因:
RHEL 8系统上,Pandas依赖的numpy与mod_wsgi存在兼容性冲突,且Python未将该兼容性错误输出,最终表现为read_sql属性找不到的异常。
内容的提问来源于stack exchange,提问作者Wige
相关产品推荐
相关产品推荐

