背景
pandas:1.5.2
sqlalchemy:2.0.4
import pandas as pd
from sqlalchemy
import create_engine # SQLAlchemy v. 2.0!
sql_engine = create_engine('postgresql://user:pass@host:5432/database')
df = pd.read_sql(f''' SELECT * FROM table LIMIT 100''',
sql_engine)
报错
Traceback (most recent call last):
File "/app/test.py", line 31, in <module>
df = pd.read_sql(f'''
File "/usr/local/lib/python3.10/site-packages/pandas/io/sql.py", line 590, in read_sql
return pandas_sql.read_query(
File "/usr/local/lib/python3.10/site-packages/pandas/io/sql.py", line 1560, in read_query
result = self.execute(*args)
File "/usr/local/lib/python3.10/site-packages/pandas/io/sql.py", line 1405, in execute
return self.connectable.execution_options().execute(*args, **kwargs)
AttributeError: 'OptionEngine' object has no attribute 'execute'
解决
https://github.com/pandas-dev/pandas/issues/40686文章来源:https://www.toymoban.com/news/detail-559778.html
在这篇文章中看到,sqlalchemy的1.4和2.0两种不同的语法,pandas暂时还不支持2.0,所以将sqlalchemy回退到1.4.45即可。文章来源地址https://www.toymoban.com/news/detail-559778.html
到了这里,关于AttributeError: ‘OptionEngine‘ object has no attribute ‘execute‘的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!