{
  "id": "python/sqlalchemy-psycopg2-binary-mismatch",
  "signature": "ImportError: dlopen(/usr/local/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so, 2): Library not loaded: libpq.5.dylib",
  "signature_zh": "ImportError: dlopen(.../psycopg2/_psycopg...so, 2): 未加载库：libpq.5.dylib",
  "regex": "ImportError:\\ dlopen\\(/usr/local/lib/python3\\.9/site\\-packages/psycopg2/_psycopg\\.cpython\\-39\\-darwin\\.so,\\ 2\\):\\ Library\\ not\\ loaded:\\ libpq\\.5\\.dylib",
  "domain": "python",
  "category": "install_error",
  "subcategory": null,
  "root_cause": "psycopg2-binary is not compatible with the system's PostgreSQL client library version, or libpq is missing.",
  "root_cause_type": "generic",
  "root_cause_zh": "psycopg2-binary 与系统的 PostgreSQL 客户端库版本不兼容，或缺少 libpq。",
  "versions": [
    {
      "version": "2.8.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2.9.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The binary wheel may still link to a different libpq version that isn't present.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "On macOS, SIP may block DYLD_LIBRARY_PATH for system binaries; not reliable.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Install psycopg2 from source instead: pip install psycopg2 --no-binary psycopg2 (requires PostgreSQL dev headers)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "Install libpq via Homebrew: brew install libpq && brew link --force libpq",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.83,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-04-08",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}