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

ModuleNotFoundError: No module named 'yaml' at ComfyUI startup means main.py is running under a Python that has none of ComfyUI's requirements. We reproduced it and show why installing pyyaml alone just swaps it for No module named 'torch'.

1. The error

ComfyUI v0.3.40, started with the system Python (CPython 3.13.5) instead of the environment its requirements were installed into:

Traceback (most recent call last):
  File "ComfyUI/main.py", line 11, in <module>
    import utils.extra_config
  File "ComfyUI/utils/extra_config.py", line 2, in <module>
    import yaml
ModuleNotFoundError: No module named 'yaml'

yaml is the import name of the pyyaml package, which is in ComfyUI's requirements.txt next to torch. main.py imports utils.extra_config (which does import yaml) before it touches torch, so yaml is simply the first package this Python is missing. The error does not mean pyyaml is broken; it means main.py is running under a Python that has none of ComfyUI's requirements.

2. Installing only pyyaml just moves the error

A Python with pyyaml 6.0.3 and nothing else, same ComfyUI:

Traceback (most recent call last):
  File "ComfyUI/main.py", line 128, in <module>
    import comfy.utils
  File "ComfyUI/comfy/utils.py", line 20, in <module>
    import torch
ModuleNotFoundError: No module named 'torch'

And on current ComfyUI (v0.37.0) the first import is a different one, so the same mistake shows up under another name:

Traceback (most recent call last):
  File "ComfyUI/main.py", line 25, in <module>
    from app.database.db import dependencies_available, init_db
  File "ComfyUI/app/database/db.py", line 6, in <module>
    from filelock import FileLock, Timeout
ModuleNotFoundError: No module named 'filelock'

No module named 'yaml', 'torch' or 'filelock' at startup (not from a custom node) all point to the same cause.

3. Fix: run main.py with the Python that has the requirements

Check which interpreter you are using and whether it has the packages:

$ python3 -c "import sys; print(sys.executable)"
/usr/bin/python3
$ venv/bin/python -c "import sys, yaml, filelock, torch; print(sys.executable, yaml.__version__, torch.__version__)"
venv/bin/python 6.0.3 2.9.0+cpu

Then either use that Python, or install the requirements into the one you run:

cd ComfyUI
source venv/bin/activate        # Windows: venv\Scripts\activate
python -m pip install -r requirements.txt
python main.py

With the venv's Python, v0.37.0 started and passed --quick-test-for-ci (exit code 0). Install torch first from the PyTorch index for your GPU if you need CUDA; a plain pip install -r requirements.txt takes whatever torch build PyPI gives you. On the Windows portable build, start ComfyUI with the supplied .bat files (they use python_embeded\python.exe) rather than python main.py from a terminal, and install packages with python_embeded\python.exe -m pip install ....

Related: ComfyUI: No module named 'numpy' · ComfyUI: No module named 'PIL' · ComfyUI: No module named 'aiohttp' · ComfyUI: No module named 'transformers' · ComfyUI: No module named 'tqdm' · ComfyUI: No module named 'torchsde' · ComfyUI: No module named 'torch_directml' · Python: No module named 'yaml' · ComfyUI: No module named 'sqlalchemy' · ComfyUI: No module named 'av' · ComfyUI-Manager: No module named 'comfy'

Frequently asked questions

Should I pip install yaml?

No. The package is pyyaml, and installing just it only reveals the next missing one (torch). Install requirements.txt into the Python that runs main.py.

Why does newer ComfyUI say No module named 'filelock' instead?

v0.37.0 imports its database module (filelock) before utils.extra_config (yaml), so the first missing package changes. Same cause, same fix.

Written with AI assistance. Measured on 2026-10-24 on Linux: ComfyUI v0.3.40 and v0.37.0 run with system CPython 3.13.5, with a venv holding only pyyaml 6.0.3, and with a full venv (CPython 3.11.17, torch 2.9.0+cpu). Output pasted unedited except shortened paths. PlainTables is our extension; ComfyUI and pyyaml are free.