Environment
- OS: macOS (Apple Silicon, M4 Pro)
- Python: 3.11 (venv)
- dbt-fabric: latest
- ODBC Driver: Microsoft ODBC Driver 18 for SQL Server (installed via
brew install msodbcsql18)
- unixODBC: installed via Homebrew (
brew install unixodbc)
Error
ImportError: dlopen(/path/to/.venv/lib/python3.11/site-packages/pyodbc.cpython-311-darwin.so, 0x0002):
Library not loaded: /opt/homebrew/opt/unixodbc/lib/libodbc.2.dylib
Referenced from: pyodbc.cpython-311-darwin.so
Reason: tried:
'/opt/homebrew/opt/unixodbc/lib/libodbc.2.dylib' (no such file)
'/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/unixodbc/lib/libodbc.2.dylib' (no such file)
Steps to Reproduce
# 1. Create venv, install dbt-fabric
python3.11 -m venv .venv && source .venv/bin/activate
pip install dbt-fabric
# 2. Install ODBC deps via Homebrew
brew install unixodbc msodbcsql18
# 3. Run dbt debug
dbt debug --profiles-dir .
# → ImportError: Library not loaded: libodbc.2.dylib
Root Cause
pyodbc is compiled against libodbc.2.dylib. Homebrew on newer macOS versions (especially post-Sonoma on Apple Silicon) ships libodbc.3.dylib instead. The binary dependency path is baked into the compiled .so and doesn't fall back gracefully.
Specifically, when pip install pyodbc builds from source (or pulls a wheel compiled on an older Homebrew), it links against libodbc.2. But Homebrew's current unixODBC ships libodbc.3.
Verification:
ls /opt/homebrew/opt/unixodbc/lib/
# libodbc.3.dylib ← exists
# libodbc.2.dylib ← MISSING (this is what pyodbc expects)
Workaround (took 2+ hours to discover)
# Reinstall pyodbc after ensuring unixodbc is on PATH
export LDFLAGS="-L/opt/homebrew/opt/unixodbc/lib"
export CPPFLAGS="-I/opt/homebrew/opt/unixodbc/include"
pip install --force-reinstall --no-binary :all: pyodbc
OR create a symlink:
ln -s /opt/homebrew/opt/unixodbc/lib/libodbc.3.dylib /opt/homebrew/opt/unixodbc/lib/libodbc.2.dylib
Ask
- Add macOS setup section to README/docs — specifically calling out the
LDFLAGS/CPPFLAGS env vars required when installing in a venv on Apple Silicon
- Consider pinning or documenting tested pyodbc wheel versions for macOS targets
- Better error output — the current dbt error log swallows the ImportError; surface it more clearly in
dbt debug output so users don't spend hours debugging a dylib path issue
This is a blocking install failure on Apple Silicon Macs. The current docs only say 'install unixODBC' which is insufficient — the version compatibility between pyodbc's compiled binary and Homebrew's libodbc is the real issue.
Encountered while building a healthcare analytics dbt-fabric project on Mac M4 Pro. Workaround verified.
Environment
brew install msodbcsql18)brew install unixodbc)Error
Steps to Reproduce
Root Cause
pyodbcis compiled againstlibodbc.2.dylib. Homebrew on newer macOS versions (especially post-Sonoma on Apple Silicon) shipslibodbc.3.dylibinstead. The binary dependency path is baked into the compiled.soand doesn't fall back gracefully.Specifically, when
pip install pyodbcbuilds from source (or pulls a wheel compiled on an older Homebrew), it links againstlibodbc.2. But Homebrew's current unixODBC shipslibodbc.3.Verification:
Workaround (took 2+ hours to discover)
OR create a symlink:
Ask
LDFLAGS/CPPFLAGSenv vars required when installing in a venv on Apple Silicondbt debugoutput so users don't spend hours debugging a dylib path issueThis is a blocking install failure on Apple Silicon Macs. The current docs only say 'install unixODBC' which is insufficient — the version compatibility between pyodbc's compiled binary and Homebrew's libodbc is the real issue.
Encountered while building a healthcare analytics dbt-fabric project on Mac M4 Pro. Workaround verified.