[Python] Why is pandas saying that 'Engine' object has no attribute 'cursor'?

Discussão em 'Python' iniciado por Stack, Maio 19, 2025.

  1. Stack

    Stack Membro Participativo

    I'm upgrading my repo from Python 3.7 to 3.13. This is a very big jump, so I need to update many packages as well. One such package is pandas.

    Upon upgrading to pandas 2.2.3 (the first version which can support 3.13 from what I understand), some of my code doesn't work anymore. Could anyone help me debug what exactly is wrong?

    The code:

    dbservice.py:

    import pandas as pd
    class DatabaseExtension(DBExtension):
    _pd = pd

    def get_dataframe(self, query, *params, **kwargs):
    query = self.build_query(query, *params)
    return self._pd.read_sql(query, self.engine, params=params, **kwargs)


    The error:

    File "C:\Users\wackowskin\PycharmProjects\Webapp\app\resources\database\dbservice.py", line 149, in get_dataframe
    return self._pd.read_sql(sql=query, con=self.engine, params=params, **kwargs)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\wackowskin\PycharmProjects\webapp\venv\Lib\site-packages\pandas\io\sql.py", line 706, in read_sql
    return pandas_sql.read_query(

    File "C:\Users\wackowskin\PycharmProjects\webapp\venv\Lib\site-packages\pandas\io\sql.py", line 2738, in read_query
    cursor = self.execute(sql, params)
    File "C:\Users\wackowskin\PycharmProjects\webapp\venv\Lib\site-packages\pandas\io\sql.py", line 2672, in execute
    cur = self.con.cursor()
    ^^^^^^^^^^^^^^^
    AttributeError: 'Engine' object has no attribute 'cursor'


    I've tried changing how the parameters are called in the function call for self._pd.read_sql() and I've tried adjusting what version of pandas I'm using, but I can't go lower than 2.2.3 since it appears none of the earlier ones support Python 3.13. Does anyone have any idea what I might need to change?

    Continue reading...

Compartilhe esta Página