2

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.

Brian Postow
  • 11,709
  • 17
  • 81
  • 125

3 Answers3

3

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.

Brian Postow
  • 11,709
  • 17
  • 81
  • 125
0

BETTER solution:

export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/opt/homebrew/lib
Brian Postow
  • 11,709
  • 17
  • 81
  • 125
  • Somehow this STOPPED WORKING? it's no longer looking at DYLD_LIBRARY_PATH? It's just looking straight to /usr/local/lib? (I set DYLD_.... to empty and it still looks in usr/local/lib...) – Brian Postow May 05 '22 at 18:28
0

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
Cyberbeni
  • 660
  • 4
  • 15