ComfyUI: ModuleNotFoundError: No module named 'sqlalchemy' (fix)

ModuleNotFoundError: No module named 'sqlalchemy' after a ComfyUI update means the new requirements were never installed. We reproduced it on v0.37.0, fixed it, and checked the softer case where only alembic is missing.

1. The error

ComfyUI v0.37.0 on CPython 3.11 with torch 2.9.0+cpu and every requirement installed except SQLAlchemy, python main.py --cpu:

[WARNING] ------------------------------------------------------------------------
Error importing dependencies: No module named 'sqlalchemy'
Please install the updated requirements.txt file by running:
venv/bin/python -m pip install -r ComfyUI/requirements.txt
If you are on the portable package you can run: update\update_comfyui.bat to solve this problem.
This error is happening because ComfyUI now uses a local sqlite database.
------------------------------------------------------------------------
Traceback (most recent call last):
  File "ComfyUI/main.py", line 26, in <module>
    from app.assets.lifecycle import cleanup_temp_filesystem
  File "ComfyUI/app/assets/lifecycle.py", line 16, in <module>
    from sqlalchemy import select
ModuleNotFoundError: No module named 'sqlalchemy'

Two things happen. app/database/db.py catches the ImportError and prints the warning box, but then main.py line 26 imports app.assets.lifecycle, which does from sqlalchemy import select unguarded, so ComfyUI exits. SQLAlchemy has been in requirements.txt since v0.3.41 (SQLAlchemy>=2.0.0 in v0.37.0) for the local SQLite asset database, so this hits installs that updated the code with git pull but never re-ran the requirements.

2. Fix: install the requirements into the Python that runs ComfyUI

cd ComfyUI
python -m pip install -r requirements.txt

Run it with the same python that starts main.py; the warning prints that exact command with the full interpreter path, which is the safest one to copy. On the Windows portable package the warning suggests update\update_comfyui.bat. After reinstalling SQLAlchemy 2.1.6 and alembic 1.20.1, the same command started without the warning and --quick-test-for-ci exited with status 0.

3. No module named 'alembic': a warning, not a crash

With SQLAlchemy present but alembic missing, v0.37.0 prints the same box and keeps going (--quick-test-for-ci exit status 0):

[WARNING] ------------------------------------------------------------------------
Error importing dependencies: No module named 'alembic'
Please install the updated requirements.txt file by running:
venv/bin/python -m pip install -r ComfyUI/requirements.txt
If you are on the portable package you can run: update\update_comfyui.bat to solve this problem.
This error is happening because ComfyUI now uses a local sqlite database.
------------------------------------------------------------------------

ComfyUI runs, but the database is off: setup_database() returns early when dependencies_available() is false, and with --enable-assets the asset endpoints answer 503. The same try block also imports blake3, so a missing blake3 gives the same warning. The fix is the same pip install -r requirements.txt.

Related: ComfyUI: No module named 'yaml' (wrong Python) · ComfyUI: No module named 'av' · ComfyUI: No module named 'torchaudio'

Frequently asked questions

Why does ComfyUI need SQLAlchemy?

ComfyUI now keeps a local SQLite database for assets; app/database and app/assets import SQLAlchemy and alembic.

Is the 'Error importing dependencies' box fatal?

Not by itself: db.py catches it. With SQLAlchemy missing, v0.37.0 then crashes in app/assets/lifecycle.py. With only alembic or blake3 missing it starts with the database disabled.

Written with AI assistance. Measured on 2026-10-24 on Linux, CPython 3.11.17: ComfyUI v0.37.0 with torch 2.9.0+cpu, without SQLAlchemy, without alembic, and with SQLAlchemy 2.1.6 + alembic 1.20.1. Output pasted unedited except shortened paths and removed INFO lines. PlainTables is our extension; ComfyUI and SQLAlchemy are free.