How to fix work on MS SQL Server

Ирина Грачева 0 Reputation points
2025-10-06T15:01:58.9166667+00:00

I've run Python 3.10.18 to create a connection to MS SQL Server DB 17 on macOS 15.6.1 and I get the error:

The issue in the driver or the python wrapper.

Fatal Python error: Segmentation fault

Extension modules: charset_normalizer.md, google._upb._message, snappy._snappy, lz4._version, lz4.frame._frame, lxml._elementpath, lxml.etree, yaml._yaml, grpc._cython.cygrpc, sqlalchemy.cimmutabledict, sqlalchemy.cprocessors, sqlalchemy.cresultproxy, pyodbc (total: 13)

Min reprodusible example:

from sqlalchemy import create_engine, text

db_connection_str = 'mssql+pyodbc://admin:password@localhost:1433/master?driver=ODBC+Driver+17+for+SQL+Server'

engine = create_engine(db_connection_str)

# Connect to the database

with engine.connect() as connection:

# Example: Execute a simple query

result = connection.execute(text("SELECT GETDATE()"))

for row in result:

print(f"Current SQL Server date: {row[0]}")

I tried this question without success. There were no such a problem three days before(03.10.2025). I've tried to clear cache and reinstall MS SQL drivers and Python without any success.

How to fix this?

SQL Server Database Engine
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Akhil Gajavelly 645 Reputation points Microsoft External Staff Moderator
    2025-10-07T04:11:48.4333333+00:00

    Hi @Ирина Грачева,

    Try the following minimal script using a downgraded pyodbc:

    import pyodbc
    conn_str = ("DRIVER={ODBC Driver 17 for SQL Server};"
    "SERVER=localhost,1433;"
    "UID=admin;PWD=password;"
    "DATABASE=master;")
    print("Connecting …")
    conn = pyodbc.connect(conn_str)
    cursor = conn.cursor()
    cursor.execute("SELECT GETDATE()")
    row = cursor.fetchone()
    print("SQL Server date:", row[0])
    conn.close()
    print("Done")

    • Run it under a debugger (lldb / gdb) so you catch the segfault stack.
    • If it works, then try via SQLAlchemy.
    • If it fails, try the same with pyodbc==4.0.32

    There are known issues with newer pyodbc builds on macOS causing segmentation faults with the ODBC 17 driver. Using version 4.0.32 usually fixes it.

    Regards, Akhil.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.