# 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`
- **Domain:** python
- **Category:** install_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

psycopg2-binary is not compatible with the system's PostgreSQL client library version, or libpq is missing.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 2.8.x | active | — | — |
| 2.9.x | active | — | — |

## Workarounds

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

## Dead Ends

- **** — The binary wheel may still link to a different libpq version that isn't present. (70% fail)
- **** — On macOS, SIP may block DYLD_LIBRARY_PATH for system binaries; not reliable. (50% fail)
