python install_error ai_generated true

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

ModuleNotFoundError: No module named 'psycopg2'

ID: python/sqlalchemy-missing-driver

其他格式: JSON · Markdown 中文 · English
80%修复率
90%置信度
0证据数
2025-08-01首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

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

English

The database driver for PostgreSQL is not installed in the Python environment.

generic

解决方案

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

无效尝试

常见但无效的做法:

  1. Installing a different driver without changing the connection string 70% 失败

    The connection string still references psycopg2.

  2. Using a virtual environment without activating it 80% 失败

    The module is installed but not accessible.