Changing location of libodbc.2.dylib on macOS
See original GitHub issueEnvironment
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:
- Created 4 years ago
- Reactions:1
- Comments:15 (3 by maintainers)
Top Related StackOverflow Question
Want to update the issue with my solution.
The clang issues can be solved by adding unixODBC’s path to these environmental variables:
This makes it possible to run
pip install --no-binary pyodbc pyodbcwith 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.
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.