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

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  1. 90% 成功率
    Install psycopg2 from source instead: pip install psycopg2 --no-binary psycopg2 (requires PostgreSQL dev headers)
  2. 80% 成功率
    Install libpq via Homebrew: brew install libpq && brew link --force libpq

无效尝试

常见但无效的做法:

  1. 70% 失败

    The binary wheel may still link to a different libpq version that isn't present.

  2. 50% 失败

    On macOS, SIP may block DYLD_LIBRARY_PATH for system binaries; not reliable.