python
install_error
ai_generated
true
ImportError: dlopen(/usr/local/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so, 2): Library not loaded: libpq.5.dylib
ID: python/sqlalchemy-psycopg2-binary-mismatch
80%Fix Rate
83%Confidence
0Evidence
2024-04-08First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2.8.x | active | — | — | — |
| 2.9.x | active | — | — | — |
Root Cause
psycopg2-binary is not compatible with the system's PostgreSQL client library version, or libpq is missing.
generic中文
psycopg2-binary 与系统的 PostgreSQL 客户端库版本不兼容,或缺少 libpq。
Workarounds
-
90% success
Install psycopg2 from source instead: pip install psycopg2 --no-binary psycopg2 (requires PostgreSQL dev headers)
-
80% success
Install libpq via Homebrew: brew install libpq && brew link --force libpq
Dead Ends
Common approaches that don't work:
-
70% fail
The binary wheel may still link to a different libpq version that isn't present.
-
50% fail
On macOS, SIP may block DYLD_LIBRARY_PATH for system binaries; not reliable.