pyodbc.Error: ('01000', “[01000] [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found (0) (SQLDriverConnect)”)

I am new to docker and python. I am running a docker image for tensorflow for image classification in Windows 10. I like to save the output into HOST SQL Server. I have modified the python code for the insert. pyodbc was not working initially. But I have run below commands and it is working.

RUN
apt-get update && apt-get install -y gcc unixodbc-dev

RUN
pip install pyodbc

But I am still getting the below error while try to run the insert python script. What should I do next?

pyodbc.Error: (‘01000’, “[01000] [unixODBC][Driver Manager]Can’t open lib ‘SQL Server’ : file not found (0) (SQLDriverConnect)”)

cnxn = pyodbc.connect(‘Trusted_Connection=yes’, driver = ‘{SQL Server}’,server = ‘127.0.0.1’, port=‘1433’, user=‘sa’, password=’*****’, database=’****’)

1 Like

Did you manage to find any solution this ?

I came across this recently. For whomever needs this:
Version → Driver Name
ODBC Driver 17 → ODBC Driver 17 for SQL Server
ODBC Driver 18 → ODBC Driver 18 for SQL Server
And here’s Microsoft’s documentation on how to install their driver on linux.

Here’s my docker file snippet that handles ODBC Driver from Microsoft, where VERSION_ID is the os version provided as an ARG variable:

ADD "https://packages.microsoft.com/config/debian/${VERSION_ID}/packages-microsoft-prod.deb" ./
RUN dpkg -i ./packages-microsoft-prod.deb \
    && rm ./packages-microsoft-prod.deb \
    && apt-get update \
    && apt-get upgrade -y --no-install-recommends \
    && ACCEPT_EULA=Y apt-get install -y --no-install-recommends \
        libgssapi-krb5-2 \
        msodbcsql18 \
        unixodbc \
        unixodbc-dev  \
    && rm -rf /var/lib/apt/lists/* \

This works on python:3.12-slim.