Brian Postow
Brian Postow

Reputation: 12187

Installing pyodbc and unixodbc on a mac

I've seen Pypyodbc: Can't open lib 'FreeTDS' : file not found") error when trying to connect to SQL server, but. that's 7 years old, and doesn't seem to be working for me, possibly because brew appears to be putting things in different places now?

I've used brew to install unixodbc, it's in /opt/homebrew/Cellar.

When I do pip install pyodbc, it appears to work, but I get:

 connection = pyodbc.connect(connection_string)
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/usr/local/lib/libtdsodbc.so' : file not found (0) (SQLDriverConnect)")

which is obviously wrong, because libtdsodbc is in /opt/homebrew/lib

I tried editing odbcinst.ini, but I'm not sure where that's supposed to live. There wasn't one in /etc, or a /etc/unixODBC directory... and when I create either one, the don't seem to be read, because it still complains about /usr/local/lib...

ETA: This is on a new Macbook, so on one of the new M1 chips.

Upvotes: 3

Views: 5712

Answers (4)

Callum Dempsey Leach
Callum Dempsey Leach

Reputation: 51

So Unix ODBC had its ODBC drivers moved to /usr/lib/libiodbcinst.2.dylib. See: https://packages.debian.org/sid/libodbcinst2

Open the ODBC driver configuration file. Add the following line or similar depending where your ODBC installation is at:

ODBCInstLib=libiodbcinst.2.dylib

This ensures the ODBC driver uses the correct iODBC library (/usr/lib/libiodbcinst.2.dylib).

Your driver configuration should look like this:

[Driver]
ErrorMessagesPath=/Library/simba/spark/ErrorMessages/
LogLevel=0
LogPath=
SwapFilePath=/tmp
ODBCInstLib=libiodbcinst.2.dylib

Failing this install unix ODBC manually wherever you want and point the refs there!!

Upvotes: 0

Cyberbeni
Cyberbeni

Reputation: 710

There is a pull request that has been pretty much ignored for 13 months now by the pyodbc maintainer: https://github.com/mkleehammer/pyodbc/pull/870

You can install the forked version with this command (might need to uninstall the previous version or add extra arguments to force reinstall)

python3 -m pip install git+git://github.com/Aloisius/pyodbc.git@m1-homebrew

Upvotes: 0

Brian Postow
Brian Postow

Reputation: 12187

BETTER solution:

export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/opt/homebrew/lib

Upvotes: 1

Brian Postow
Brian Postow

Reputation: 12187

Note: This is a BAD answer in the hopes of attracting a good one, but it technically seems to be working.

Homebrew for M1 installs everything in /opt/homebrew. Everything else expects things in /usr/local. On a new computer, /usr/local/lib didn't even exist. So I did

sudo ln -s /opt/homebrew/lib /usr/local/lib

THIS IS VERY BAD AND I KNOW IT But it's the only way I've figured out currently to deal with the problem. Maybe something hasn't caught up to M1? I'm not sure.

Upvotes: 4

Related Questions