ComfyUI: module 'onnxruntime' has no attribute 'InferenceSession' (fix)

AttributeError: module 'onnxruntime' has no attribute 'InferenceSession' in ComfyUI (InstantID, insightface) happens when onnxruntime and onnxruntime-gpu were both installed and one was uninstalled. We reproduced it on v0.37.0 and fixed it.

1. The error

ComfyUI v0.37.0 (CPython 3.11) with ComfyUI_InstantID and insightface 2.1. ONNX Runtime had been installed twice, as onnxruntime and onnxruntime-gpu (InstantID's requirements.txt installs both on x86_64 Windows/Linux), and then onnxruntime was uninstalled to keep only the GPU build:

[WARNING] Traceback (most recent call last):
  ...
  File "ComfyUI/custom_nodes/ComfyUI_InstantID/__init__.py", line 1, in <module>
    from .InstantID import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
  File "ComfyUI/custom_nodes/ComfyUI_InstantID/InstantID.py", line 13, in <module>
    from insightface.app import FaceAnalysis
  File "venv/lib/python3.11/site-packages/insightface/__init__.py", line 35, in <module>
    from . import model_zoo
  File "venv/lib/python3.11/site-packages/insightface/model_zoo/__init__.py", line 1, in <module>
    from .model_zoo import get_model
  File "venv/lib/python3.11/site-packages/insightface/model_zoo/model_zoo.py", line 53, in <module>
    class PickableInferenceSession(onnxruntime.InferenceSession):
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'onnxruntime' has no attribute 'InferenceSession'

[WARNING] Cannot import ComfyUI/custom_nodes/ComfyUI_InstantID module for custom nodes: module 'onnxruntime' has no attribute 'InferenceSession'
[INFO]    0.0 seconds (IMPORT FAILED): ComfyUI/custom_nodes/ComfyUI_InstantID

pip list still shows onnxruntime-gpu 1.31.0, but import onnxruntime now gives a near-empty package: onnxruntime.__version__ raises AttributeError as well, and only a capi folder is left in site-packages/onnxruntime.

2. Why

Both distributions install their files into the same onnxruntime/ import package. Uninstalling one deletes the files it recorded, which are the same paths the other one uses, so the remaining distribution is broken even though pip thinks it is installed. ComfyUI keeps running (exit code 0); only the node pack is marked IMPORT FAILED.

3. Fix: force-reinstall the runtime you kept

python -m pip install --force-reinstall --no-deps onnxruntime-gpu==1.31.0

(use your installed version, from python -m pip show onnxruntime-gpu; or onnxruntime if you kept the CPU build). Afterwards onnxruntime.__version__ was 1.31.0, InferenceSession existed again, and ComfyUI loaded the node:

[INFO]    0.2 seconds: ComfyUI/custom_nodes/ComfyUI_InstantID

Keep only one of the two: insightface 2.1 itself says to install onnxruntime-gpu only after uninstalling onnxruntime. If you later run InstantID's pip install -r requirements.txt again, it installs both again. On the Windows portable build run the commands as python_embeded\python.exe -m pip ....

Related: ComfyUI: No module named 'onnxruntime' · ComfyUI: No module named 'insightface' · onnxruntime: cannot enable executable stack

Frequently asked questions

Why is onnxruntime-gpu broken after uninstalling onnxruntime?

Both distributions write the same onnxruntime/ package files, so uninstalling one deletes files the other needs. Reinstall the remaining one with --force-reinstall.

Can I keep onnxruntime and onnxruntime-gpu together?

No; insightface 2.1 tells you to keep only one ONNX Runtime distribution in the environment.

Written with AI assistance. Measured on 2026-10-24 on Linux, CPython 3.11.17: ComfyUI v0.37.0, ComfyUI_InstantID at commit 72495e8, insightface 2.1, onnxruntime and onnxruntime-gpu 1.31.0. Output pasted unedited except shortened paths and a trimmed traceback. PlainTables is our extension; ComfyUI, InstantID, insightface and ONNX Runtime are free.