2
votes

I am trying to run my python code within a Ubunu VM (18.04.3) but keep getting the error:

Traceback (most recent call last): File "python-script.py", line 33, in conn = pyodbc.connect('Driver={SQL Server Native Client 11.0};' pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'SQL Server Native Client 11.0' : file not found (0) (SQLDriverConnect)")

I have installed pyodbc with no errors so am confused as to what could be causing this issue. I have done lots of search to a solution but most are for different driver versions and do not resolve this issue. Below is my code for connecting to the DB which I believe could be causing this error:

conn = pyodbc.connect('Driver={SQL Server Native Client 11.0};'
                      'Server=servername;'
                      'Database=databasename;'
                      'Trusted_Connection=yes;')

Any help with this would be much appreciated!

1
Which version of pyodbc did you install? According to the install documentation (step 3) it's version 17, not 11.Larnu

1 Answers

3
votes

After you install the ODBC driver according to the instructions at

https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15

you need to use

DRIVER=ODBC Driver 17 for SQL Server;...