Cant find pyodbc driver despite install

10,159

I was having same issue. The only workaround I found was to pass the driver file location to the connection request. But the connection/bandwidth is extremely slow when trying to query using pyodbc (compared with using SQL Ops Studio).

import pyodbc
import pandas as pd

driver = '/usr/local/lib/libtdsodbc.so' # Change this to where FreeTDS installed the driver library!

conn = pyodbc.connect(
    driver = driver,
    TDS_Version = '7.3', 
    server = <tunneled server>,
    port = 1433,
    uid = <sql_user_id>,
    pwd = <sql_password>)

crsr = conn.cursor()
table = pd.read_sql(<sql statement>, conn)
crsr.close()
conn.close()
Share:
10,159
Rilcon42
Author by

Rilcon42

Updated on September 18, 2022

Comments

  • Rilcon42
    Rilcon42 over 1 year

    I have pyodbc installed and I am trying to connect to a server, but pyodbc can't find the drivers. I did the following:

    1. Installed pyodbc using pip:

      pip install pyodbc
      
    2. Followed the Microsoft instructions.

    3. Ran a test script:

      import pyodbc 
      
      print(pyodbc.drivers())
      

      which returned an empty array.

    What else do I need to do? I'm running the script in a Jupyter Notebook inside an Anaconda Python install.

  • Raihan Shafique
    Raihan Shafique over 4 years
    In my case my driver was in the following location in ubuntu18.04LTS /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.4.so.1.1 And I used the above suggestion and it worked perfectly.