python module_error ai_generated true

ImportError: No module named 'flask_sqlalchemy'

ID: python/flask-import-error-flask-sqlalchemy-not-installed

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2024-02-18First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

Flask-SQLAlchemy extension is not installed in the environment.

generic

中文

环境中未安装 Flask-SQLAlchemy 扩展。

Workarounds

  1. 95% success Install Flask-SQLAlchemy
    pip install flask-sqlalchemy
    # Then import: from flask_sqlalchemy import SQLAlchemy
  2. 90% success Use virtual environment and install
    python -m venv venv
    source venv/bin/activate
    pip install flask flask-sqlalchemy

Dead Ends

Common approaches that don't work:

  1. Installing with pip install flask-sqlalchemy but using wrong import name 70% fail

    Import name is flask_sqlalchemy, not flask-sqlalchemy.

  2. Assuming it's included with Flask 80% fail

    Flask-SQLAlchemy is a separate package.