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

ModuleNotFoundError: No module named 'torchsde' stops ComfyUI itself, not a custom node: its core sampler file imports torchsde at startup. We reproduced it on ComfyUI v0.37.0 and fixed it with one pip command.

1. The error

ComfyUI v0.37.0 (Python 3.11, torch 2.9.0 CPU) started in a venv where torchsde was missing:

python main.py --cpu
Traceback (most recent call last):
  File "/path/to/ComfyUI/main.py", line 251, in <module>
    import execution
  File "/path/to/ComfyUI/execution.py", line 25, in <module>
    import nodes
  File "/path/to/ComfyUI/nodes.py", line 24, in <module>
    import comfy.samplers
  File "/path/to/ComfyUI/comfy/samplers.py", line 4, in <module>
    from .k_diffusion import sampling as k_diffusion_sampling
  File "/path/to/ComfyUI/comfy/k_diffusion/sampling.py", line 7, in <module>
    import torchsde
ModuleNotFoundError: No module named 'torchsde'
exit 1

This is not a custom node failing to load. comfy/k_diffusion/sampling.py (the core samplers) has import torchsde at line 7, and main.py imports it through nodes.py at startup, so ComfyUI exits with code 1 before any custom node is loaded and the web UI never starts. torchsde is listed in ComfyUI's own requirements.txt; seeing this error means those requirements were not installed into the Python that runs main.py (a new venv, a different Python, or an update that added packages).

2. Fix: install it with ComfyUI's Python

cd ComfyUI
python -m pip install torchsde
Using Python 3.11.17 environment at: /path/to/venv
Resolved 13 packages in 86ms
Installed 1 package in 3ms
 + torchsde==0.2.6

(We used uv pip; plain pip does the same.) torchsde 0.2.6 depends on numpy, scipy, torch and trampoline, all pulled in automatically. Better still, install the whole file so the next missing package does not stop you too: python -m pip install -r requirements.txt. Use the same interpreter that starts ComfyUI: activate its venv first, or on the Windows portable build run python_embeded\python.exe -m pip install torchsde from the portable folder.

Restarted, ComfyUI got through startup and loaded all custom nodes, exit code 0:

Import times for custom nodes:
[INFO]    0.0 seconds: /path/to/ComfyUI/custom_nodes/websocket_image_save.py
[INFO]    0.0 seconds: /path/to/ComfyUI/custom_nodes/comfyui-various
[INFO]    0.0 seconds: /path/to/ComfyUI/custom_nodes/ComfyUI-GGUF
[INFO]    0.1 seconds: /path/to/ComfyUI/custom_nodes/ComfyUI-Impact-Subpack
[INFO]    0.3 seconds: /path/to/ComfyUI/custom_nodes/ComfyUI_InstantID
[INFO] 
[INFO] Context impl SQLiteImpl.
[INFO] Will assume non-transactional DDL.
[INFO] Using RAM pressure cache.
exit 0

Related: ComfyUI: No module named 'yaml' (same cause: requirements not installed) · ComfyUI: No module named 'av' · ComfyUI: No module named 'sqlalchemy' · ComfyUI: No module named 'torchaudio'

Frequently asked questions

Is torchsde part of PyTorch?

No. It is a separate package (stochastic differential equation solvers) that ComfyUI's requirements.txt lists; installing torch does not install it.

Why does ComfyUI not start at all?

comfy/k_diffusion/sampling.py imports torchsde at module level and main.py imports it via nodes.py, so the error happens before the server starts.

Written with AI assistance. Measured on 2026-10-24 on Linux, CPython 3.11.17: ComfyUI v0.37.0, torch 2.9.0+cpu, torchsde 0.2.6 removed and reinstalled, main.py --cpu --quick-test-for-ci. Output pasted unedited except shortened paths. PlainTables is our extension; ComfyUI and torchsde are free.