Pyodbc.drivers() returning an empty list on Mac
Asked Answered
J

1

5

I'm attempting to access an SQL Database using sqlalchemy, but I seemingly don't have any ODBC drivers installed. I've followed Microsoft's instructions on installing ODBC drivers via Homebrew here:

https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-2017

But still am turning up short. When I perform pip install pyodbc, it returns that it's installed. However, when I search for the drivers, I just get an empty list:

In[1]: import pyodbc
In[2]: pyodbc.drivers()
Out[2]: []

Thanks in advance.

Jointed answered 16/3, 2021 at 17:3 Comment(3)
Can you run odbcinst -j at a command prompt? If so, check the contents of the odbcinst.ini file listed as the DRIVERS... location.Kosak
DRIVERS location is: /etc/odbcinst.ini; the USER DATA SOURCES..: /Users/MYUSERNAME/.odbc.ini. When I go to the file path, no files exist. If I try to open it at the command prompt, I get an error stating no programs know how to open the file.Jointed
So if you try cat /etc/odbcinst.ini you get "No such file or directory"?Kosak
P
8

Some users encounter an issue when trying to connect after installing the ODBC driver and receive an error like: "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)". It may be the case that unixODBC is not configured correctly to find registered drivers. In these cases, creating a couple symbolic links can resolve the issue.

sudo ln -s /usr/local/etc/odbcinst.ini /etc/odbcinst.ini
sudo ln -s /usr/local/etc/odbc.ini /etc/odbc.ini

The above works for me. ref

Peterman answered 6/4, 2021 at 7:41 Comment(1)
For M1 macs, the above symlinks might be invalid. This is because the homebrew directory on M1s is /opt/homebrew instead of Intel's /usr/local. Thus the paths should be adjusted accordingly.Kristeenkristel

© 2022 - 2024 — McMap. All rights reserved.