Changing location of libodbc.2.dylib on macOS

See original GitHub issue

Environment

To diagnose, we usually need to know the following, including version numbers. On Windows, be sure to specify 32-bit Python or 64-bit:

  • Python: 3.7.6
  • pyodbc: 4.0.28
  • OS: macOS 10.14.4
  • driver: freetds

Issue

When importing pyodbc

❯ python
>>> import pyodbc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/pcosta/Documents/test/myenv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
  Referenced from: /Users/pcosta/Documents/test/myenv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
  Reason: image not found

I know why this is happening, as I don’t have libodbc.2.dylib in the expected location. The reason is I do not have permission to write to /usr/local/, so I have Homebrew installing into ~/.brew. This mostly works fine. I am even able to get both tsql and isql working as expected by following the steps outlined here: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Mac-OSX.

So I do have libodbc.2.dylib, it’s just that it lives in /Users/pcosta/.brew/opt/unixodbc/lib, not /usr/local/opt/unixodbc/lib.

The main questions is can I get pyodbc to look for libodbc.2.dylib (and other associated files) in another directory?

I have all the files needed and have configured them correctly, I just need to repoint pyodbc somehow.

Thanks!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
paw-lucommented, Jan 16, 2020

Want to update the issue with my solution.

The clang issues can be solved by adding unixODBC’s path to these environmental variables:

export LDFLAGS="-L/Users/pcosta/homebrew/opt/unixodbc/lib $LDFLAGS"
export CPPFLAGS="-I/Users/pcosta/homebrew/opt/unixodbc/include $CPPFLAGS"
export PKG_CONFIG_PATH="/Users/pcosta/homebrew/opt/unixodbc/lib/pkgconfig $PKG_CONFIG_PATH"

This makes it possible to run pip install --no-binary pyodbc pyodbc with an atypical installation directory.

It would be nice if users would be able to specify locations of drivers to avoid the build process, but I realize this is a specific edge case.

1reaction
fonnesbeckcommented, Dec 2, 2020

Yes, I spent an afternoon spinning my wheels on this one. If you install your unixODBC and FreeTDS via MacPorts, you are just. out of luck–pyodbc will not see them. It would be nice to have an package installer-agnostic way of making all this work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Change where pyodbc expects libodbc.2.dylib to live ...
dylib in the expected location. The reason is I do not have permission to write to /usr/local/ , so I have Homebrew installing...
Read more >
Developers - Changing location of libodbc.2.dylib on macOS -
Python: 3.7.6; pyodbc: 4.0.28; OS: macOS 10.14.4; driver: freetds. Issue ... I know why this is happening, as I don't have libodbc.2.dylib in...
Read more >
Using the Microsoft ODBC Driver for SQL Server on Linux and ...
dylib into Omnis' Frameworks folder and/or make sure that the symbolic link libodbc.dylib exists and points to libodbc.2.dylib. Remember to set the ODBC...
Read more >
ODBC 3.x Troubleshooting: UNIX Configuration - Safe Software
2 (latest) provides a compatible libodbc.2.dylib. On OSX, the environmental variable DYLD_LIBRARY_PATH must contain a path that contains the ODBC library. By ...
Read more >
Installing ODBC via HomeBrew - Apple StackExchange
... Server : Can't open lib 'ODBC Driver 13 for SQL Server'. See: Installing the Microsoft ODBC Driver for SQL Server on Linux...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found