AttributeError: 'Engine' object has no attribute 'execute'
时间: 2023-08-12 09:04:58 浏览: 373
Engine.exe
引用\[1\]:报错 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' 解决 。
引用\[2\]: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) 。
问题:AttributeError: 'Engine' object has no attribute 'execute'
回答: 这个错误是由于在使用pandas的read_sql函数时,出现了'OptionEngine' object has no attribute 'execute'的错误。这个错误通常是由于pandas和SQLAlchemy版本不兼容导致的。根据引用\[2\]中提供的信息,你使用的pandas版本是1.5.2,而SQLAlchemy版本是2.0.4。为了解决这个问题,你可以尝试升级pandas和SQLAlchemy到兼容的版本。另外,你还可以尝试使用不同的方法来执行SQL查询,例如使用SQLAlchemy的execute函数来执行查询。希望这些信息对你有帮助。
#### 引用[.reference_title]
- *1* *2* [AttributeError: ‘OptionEngine‘ object has no attribute ‘execute](https://blog.csdn.net/qq_28668779/article/details/129238395)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文