# ImportError: dlopen(.../psycopg2/_psycopg...so, 2): 未加载库：libpq.5.dylib

- **ID:** `python/sqlalchemy-psycopg2-binary-mismatch`
- **领域:** python
- **类别:** install_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

psycopg2-binary 与系统的 PostgreSQL 客户端库版本不兼容，或缺少 libpq。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.8.x | active | — | — |
| 2.9.x | active | — | — |

## 解决方案

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
   ```

## 无效尝试

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