# ModuleNotFoundError: 没有名为 'psycopg2' 的模块

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

## 根因

Python 环境中未安装 PostgreSQL 数据库驱动程序。

## 版本兼容性

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

## 解决方案

1. **Install psycopg2 using pip** (95% 成功率)
   ```
   pip install psycopg2-binary
   ```
2. **Switch to a different driver like asyncpg** (85% 成功率)
   ```
   # Change connection string to use asyncpg
engine = create_engine('postgresql+asyncpg://user:pass@localhost/db')
   ```

## 无效尝试

- **Installing a different driver without changing the connection string** — The connection string still references psycopg2. (70% 失败率)
- **Using a virtual environment without activating it** — The module is installed but not accessible. (80% 失败率)
