python
install_error
ai_generated
true
ModuleNotFoundError: 没有名为 'psycopg2' 的模块
ModuleNotFoundError: No module named 'psycopg2'
ID: python/sqlalchemy-missing-driver
80%修复率
90%置信度
0证据数
2025-08-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
Python 环境中未安装 PostgreSQL 数据库驱动程序。
English
The database driver for PostgreSQL is not installed in the Python environment.
解决方案
-
95% 成功率 Install psycopg2 using pip
pip install psycopg2-binary
-
85% 成功率 Switch to a different driver like asyncpg
# Change connection string to use asyncpg engine = create_engine('postgresql+asyncpg://user:pass@localhost/db')
无效尝试
常见但无效的做法:
-
Installing a different driver without changing the connection string
70% 失败
The connection string still references psycopg2.
-
Using a virtual environment without activating it
80% 失败
The module is installed but not accessible.