7

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.

Rilcon42
  • 251

1 Answers1

4

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()
geominded
  • 155