Skip to content

Fix ComfyUI ImportError cannot import name __version__ from pydantic_core

In the ComfyUI community, a common issue has been cropping up lately where users encounter a specific failure during the initialization sequence. The error message usually looks like this: ImportError: cannot import name '__version__' from 'pydantic_core' (unknown location).

This error is particularly frustrating because it often happens after an update to a custom node or the ComfyUI core itself, even if you haven’t manually touched your pip packages.

This error typically indicates a corrupted installation or a version mismatch between pydantic and pydantic-core. Since Pydantic v2, the core logic is moved to a Rust-based binary package (pydantic-core). If the metadata points to a version that isn’t fully installed or if there are “ghost” files from a previous version, the import fails.

The Immediate Fix: Force a clean re-installation of both packages within your specific environment.

Terminal window
# For standard Python environments (Python 3.10, 3.11, 3.12)
python -m pip install --upgrade --force-reinstall pydantic pydantic-core

The transition from Pydantic V1 to V2 was a massive architectural shift. Pydantic V2 relies on pydantic-core, a separate package containing compiled binaries. ComfyUI and its ecosystem of custom nodes often have conflicting dependency requirements.

If one node requires pydantic>=2.0 and another attempts to fallback to v1, or if a pip install was interrupted, you end up with a state where the Python wrapper for Pydantic expects certain attributes (like __version__) from the binary core that simply aren’t there or are incompatible.

Section titled “Solution 1: The Clean Reinstall (Recommended)”

This is the most reliable fix. By using --force-reinstall, you tell pip to ignore the cached versions and current state, ensuring that the binary links are correctly established.

Note for Portable ComfyUI Users: If you are using the “Portable” version of ComfyUI (the .7z or .zip release), you cannot just run pip globally. You must use the embedded Python executable.

Terminal window
# Illustrative example — run from your ComfyUI_windows_portable folder
.\python_embeded\python.exe -m pip install --upgrade --force-reinstall pydantic pydantic-core

Sometimes pip fails to overwrite existing .dist-info folders, leading to a “zombie” installation where Python thinks a package is present but cannot load it.

  1. Navigate to your environment’s site-packages directory.
  2. Locate any folders starting with pydantic or pydantic_core.
  3. Delete them manually.
  4. Run a fresh install:
Terminal window
# Python 3.10+ illustrative example
pip install pydantic

In rare cases, another library might be bundling an older version of pydantic_core in a way that shadows the main installation.

Check for conflicting versions by running:

Terminal window
# Python 3.10+
pip list | grep pydantic

If you see pydantic at version 1.x.x but pydantic-core is also present, you have a conflict. Pydantic V1 does not use pydantic-core. You should upgrade your environment to V2 unless a specific legacy node strictly requires V1.


To avoid breaking your ComfyUI environment in the future, follow these practices:

  • Isolate Environments: Never install ComfyUI dependencies into your global system Python. Use venv or Conda.
  • Check Custom Node Requirements: Before installing a new custom node, check its requirements.txt. If it pins pydantic==1.10.x, it will likely break a modern ComfyUI setup.
  • Use the Manager: Use the ComfyUI-Manager custom node to install requirements. It handles many of these conflicts by running the correct pip flags under the hood.

Does this error mean my GPU drivers are out of date? No. This is strictly a Python packaging issue. It relates to how libraries are loaded into memory and has no direct connection to your CUDA or GPU driver version.

What if I need Pydantic V1 for a specific non-ComfyUI project? This is why Virtual Environments are critical. You can have pydantic==1.10 in one folder for an old project and pydantic==2.x in your ComfyUI folder without them ever seeing each other.

I reinstalled, but now I get “AttributeError: module pydantic has no attribute Field”? This usually happens when you have a file named pydantic.py in your working directory. Python sees that file first and tries to import from it instead of the actual library. Ensure no local files share names with major libraries.