Resolved Pandas requires version '1.4.0' or newer of 'sqlalchemy' (version '0.7.10' currently installed).

Solved (pandas + sqlalchemy read database error) Pandas requires version '1.4.0' or newer of 'sqlalchemy' (version '0.7.10' currently installed).







error code

A friend of the fan group wanted to use pandas and sqlalchemy to read the database information, but an error occurred (at that time, he felt a lot of cold, and he came to me for help, and then successfully helped him solve it, by the way, I hope it can help More friends who will not solve this bug), the error code is as follows:

import pandas as pd
import sqlalchemy

engine = sqlalchemy.create_engine('mssql+pymssql://账号:密码@服务器地址:端口号/库名')

df = pd.read_excel("./text.xls")

df.to_sql("表名", con=engine, if_exists="append", index=False, chunksize=2000)

Screenshot of error message :


insert image description here

    raise ImportError(
ImportError: Unable to find a usable engine; tried using: 'sqlalchemy'.
A suitable version of sqlalchemy is required for sql I/O support.
Trying to import the above resulted in these errors:
 - Pandas requires version '1.4.0' or newer of 'sqlalchemy' (version '0.7.10' currently installed).

error translation

Error message translation :

ImportError: Could not find available engine; try 'sqlalchemy'.
SQL I/O support requires an appropriate version of sqlalchemy.
Attempting to import the above results in the following error:

  • Pandas requires '1.4.0' or higher of 'sqlalchemy' (currently installed version is '0.7.10').

Reason for error


Reason for error : Pandas requires '1.4.0' or higher version of 'sqlalchemy' (the currently installed version is '0.7.10'). Since pandas is the latest version and sqlalchemy's is too low to match.The small partner can execute the following sqlalchemy version upgrade and name! ! !


Solution


Execute the following pip command to upgrade the sqlalchemy version:

pip install --upgrade sqlalchemy

insert image description here


Running the code again after the upgrade succeeded:


insert image description here



help



This article has been included in: "Farewell to Bug" column

This column is used to record various difficult bugs encountered in study and work, as well as various problems raised by small partners in the fan group. Article format: error code + error translation + error reason + solution, including program installation, operation If you encounter other problems in the process of the program, if you encounter other problems after subscribing to the column + following the blogger, you can privately chat to help solve them! ! !

Guess you like

Origin blog.csdn.net/yuan2019035055/article/details/126346403