python
install_error
ai_generated
true
ImportError: dlopen(.../psycopg2/_psycopg...so, 2): 未加载库:libpq.5.dylib
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%修复率
83%置信度
0证据数
2024-04-08首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 2.8.x | active | — | — | — |
| 2.9.x | active | — | — | — |
根因分析
psycopg2-binary 与系统的 PostgreSQL 客户端库版本不兼容,或缺少 libpq。
English
psycopg2-binary is not compatible with the system's PostgreSQL client library version, or libpq is missing.
解决方案
-
90% 成功率
Install psycopg2 from source instead: pip install psycopg2 --no-binary psycopg2 (requires PostgreSQL dev headers)
-
80% 成功率
Install libpq via Homebrew: brew install libpq && brew link --force libpq
无效尝试
常见但无效的做法:
-
70% 失败
The binary wheel may still link to a different libpq version that isn't present.
-
50% 失败
On macOS, SIP may block DYLD_LIBRARY_PATH for system binaries; not reliable.