You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows系统Anaconda环境下pyodbc未识别ODBC Driver 17及SQL Server连接报错的解决办法

Fixing "ODBC Driver 17 not found" in Anaconda Environment

Let's walk through why you're hitting this error and how to get pyodbc recognizing ODBC Driver 17 for SQL Server in your Anaconda setup.

Why isn't ODBC Driver 17 showing up in pyodbc.drivers()?

The most common reasons are:

  • Mismatched architecture (32-bit vs 64-bit): Your Anaconda Python environment and the installed ODBC driver are different bit versions. pyodbc can only detect drivers that match the bitness of your Python runtime.
  • ODBC Driver 17 isn't installed: You haven't downloaded and installed the official ODBC Driver 17 for SQL Server from Microsoft.
  • Driver registration issue: Sometimes the driver doesn't register properly immediately after installation, or your Anaconda session hasn't picked up the system-wide driver changes yet.

Step-by-Step Fixes

1. Confirm your Anaconda Python environment's bitness

First, check if your Python is 32-bit or 64-bit. Open Anaconda Prompt, activate your environment, and run:

python -c "import sys; print('64-bit' if sys.maxsize > 2**32 else '32-bit')"

Note this result—you'll need a driver that matches this bitness.

2. Install the correct ODBC Driver 17 for SQL Server

Head to Microsoft's official download page (search for "ODBC Driver 17 for SQL Server download") and grab the installer that matches your Python's bitness:

  • If you're running 64-bit Python, download the 64-bit installer
  • If you're on 32-bit Python, download the 32-bit installer (this is easy to miss—most Windows systems are 64-bit, but some Anaconda environments might be 32-bit)

Run the installer and follow the prompts to complete installation.

3. Verify the driver is registered in ODBC Data Source Administrator

To confirm the driver is installed correctly:

  • For 64-bit drivers: Open C:\Windows\System32\odbcad32.exe
  • For 32-bit drivers: Open C:\Windows\SysWOW64\odbcad32.exe
    Go to the Drivers tab—you should see ODBC Driver 17 for SQL Server listed here.

4. Refresh your Anaconda session and recheck drivers

Close and reopen your Anaconda Prompt, activate your environment again, then run:

python -c "import pyodbc; print(pyodbc.drivers())"

You should now see ODBC Driver 17 for SQL Server in the output list. If not, try restarting your computer—sometimes driver registration requires a system reboot.

5. Update pyodbc (if needed)

If the driver is installed but still not detected, make sure you're running a recent version of pyodbc. Update it in your Anaconda environment with:

conda install -c anaconda pyodbc
# Or use pip if conda doesn't have the latest version
pip install --upgrade pyodbc

6. Fix your connection string

Now that the driver is detected, update your connection string to include all necessary parameters (server, database, credentials, etc.). A full example would look like:

conn_str = (
    "DRIVER={ODBC Driver 17 for SQL Server};"
    "SERVER=your_sql_server_name;"
    "DATABASE=your_database_name;"
    "UID=your_username;"
    "PWD=your_password"
)
conn = pyodbc.connect(conn_str)

内容的提问来源于stack exchange,提问作者Cocoa Krispy's

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 23:12:37