使用SQLAlchemy连接到数据库

Jam*_*ull 9 python sqlalchemy

我正在尝试连接到本地计算机上的数据库.

import sqlalchemy
engine = sqlalchemy.create_engine('mssql+pyodbc://localhost\\SQLEXPRESS/NCM')
Run Code Online (Sandbox Code Playgroud)

它失败并出现以下错误:

DBAPIError: (pyodbc.Error) ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
Run Code Online (Sandbox Code Playgroud)

并输出此警告:

C:\Miniconda\envs\bees\lib\site-packages\sqlalchemy\connectors\pyodbc.py:82: SAWarning: No driver name specified; this is expected by PyODBC when using DSN-less connections
"No driver name specified; "
Run Code Online (Sandbox Code Playgroud)

我应该在哪里寻找诊断问题?

Jam*_*ull 14

如此链接所示,从版本1.0.0开始,您需要为主机名连接明确指定驱动程序.

Changed in version 1.0.0: Hostname-based PyODBC connections now require the
SQL Server driver name specified explicitly. SQLAlchemy cannot choose an 
optimal default here as it varies based on platform and installed drivers.
Run Code Online (Sandbox Code Playgroud)