10

I am using Windows WSL and am trying to configure python to connect to MSSQL

I have installed https://learn.microsoft.com/en-us/sql/connect/python/pyodbc/step-1-configure-development-environment-for-pyodbc-python-development

and

https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server

But when I run the example connection as per https://learn.microsoft.com/en-us/sql/connect/python/pyodbc/step-3-proof-of-concept-connecting-to-sql-using-pyodbc I get this error:

Traceback (most recent call last):
  File "users.py", line 9, in <module>
    cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
pyodbc.Error: ('01000', u"[01000] [unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.2.so.0.1' : file not found (0) (SQLDriverConnect)")

File exists:

 khinester@win  /c/Users/norman/Projects/sysadmin   master ? ↑1 ⍟2  ls /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.2.so.0.1                                          ✔  5619  15:52:53
-rwxr-xr-x 1 root root 18M Jul  3  2018 /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.2.so.0.1

Any advice on how to fix this is much appreciated

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
khinester
  • 3,398
  • 9
  • 45
  • 88
  • too bad no replies to this. did you ever figure it out? – Ukrainian-serge Feb 16 '22 at 16:58
  • I know this is a dead thread, but you get that error most likely because you installed the ODBC Driver 18 and in the connection you call the 17 version – luigi May 04 '22 at 14:26
  • Did you check the access rights? Not sure how WSL handles these in combination with pyodbc: https://chmod-calculator.com/ Maybe you need to modify the access rights or add a certain user to a group? – Ohumeronen Feb 10 '23 at 21:22

0 Answers0