JohnM
JohnM

Reputation: 111

Can't open lib '/usr/local/lib/libmsodbcsql.13.dylib' : file not found - but file exists

I am trying to connect to an MSSQL server from a Jupyter notebook using pyodbc and unixODBC, under macOS 10.15.4. I have just upgraded OSX to Catalina and my previously working configuration has broken.

I try to connect with:

pyodbc.connect('Driver={ODBC Driver 13 for SQL Server};Server=xxx;Database=xxx;uid=xxx;pwd=xxx;')

which throws an error:

Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/usr/local/lib/libmsodbcsql.13.dylib' : file not found (0) (SQLDriverConnect)")

But this file exists, and is pointed to by the driver in obdcinst.ini, and links seem correct.

To track this through, I run:

$ odbcinst -j

unixODBC 2.3.4
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /Users/johnmorgan/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

The driver file exists, and is as follows:

$ more /etc/odbcinst.ini

[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/usr/local/lib/libmsodbcsql.13.dylib
UsageCount=1

The indicated Driver is a symlink - this is the 'file not found' file in the error:

$ ls -al /usr/local/lib/libmsodbcsql.13.dylib

lrwxr-xr-x  1 johnmorgan  admin  54 Apr 15 08:13 /usr/local/lib/libmsodbcsql.13.dylib -> ../Cellar/msodbcsql/13.1.9.2/lib/libmsodbcsql.13.dylib

and the symlink points to the actual library file:

$ ls -al /usr/local/Cellar/msodbcsql/13.1.9.2/lib/libmsodbcsql.13.dylib

-r--r--r--  1 johnmorgan  admin  2456360 Jan 29  2018 /usr/local/Cellar/msodbcsql/13.1.9.2/lib/libmsodbcsql.13.dylib

So as far as I can tell, all the drivers, files and links are all correct.

So why do I get a 'file not found' error, and how can I fix this?

I am aware of others with this problem, eg Can't open lib 'ODBC Driver 13 for SQL Server'? Sym linking issue?, but this has not helped me resolve my issue.

Upvotes: 5

Views: 6584

Answers (1)

Logan Wayne
Logan Wayne

Reputation: 5991

I had the same issue. I tried to locate the dylab file and went to /usr/local/lib/ and did not find the file. So I searched libmsodbcsql.13.dylib in Finder and luckily enough, found it at:

/opt/homebrew/Cellar/msodbcsql/13.1.9.2/lib/

My next action was to change the directory in the odbcinst.ini file which I found at

/opt/homebrew/etc/odbcinst.ini

Even after updating the correct directory in the .ini file, my project still shows file not found.

Next thing I did is I installed msodbcsql 17:

HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=Y
brew install msodbcsql17 mssql-tools

Strange enough, it worked after installing msodbcsql 17. I checked the .ini file, it was updated including the new msodbcsql 17 along with msodbcsql 13 intact inside.

Upvotes: 2

Related Questions