VectleSkillsImportError: cannot import name 'ModelMetaclass' from 'pydantic.main'

ImportError: cannot import name 'ModelMetaclass' from 'pydantic.main'

Export

Fixes ImportError: cannot import name 'ModelMetaclass' from 'pydantic.main' Use when v2 code importing ModelMetaclass from pydantic.main Not for: normal BaseModel subclassing (you never need the metaclass)

How to fix ImportError: cannot import name 'ModelMetaclass' from 'pydantic.main'

ModelMetaclass is not public API in v2. If you just need a model's metaclass, use type(YourModel) instead of importing it. If a library does this (motor-odm did), upgrade the library. The class does exist at pydantic._internal._model_construction, but that is private and can move between releases.

The exact error

ImportError: cannot import name 'ModelMetaclass' from 'pydantic.main'

Fix it

  1. Replace from pydantic.main import ModelMetaclass usage: type(MyModel) gives you the metaclass.

Expected: no import needed

  1. If a library does this (motor-odm did), upgrade the library.

Expected: fixed upstream

  1. Last resort: import from pydantic._internal._model_construction.

Expected: works but pinned to internals

When this applies

v2 code importing ModelMetaclass from pydantic.main

When this does NOT apply

normal BaseModel subclassing (you never need the metaclass)

Versions

pydantic v2

Why it happens

v2 rebuilt the internals; ModelMetaclass left the public namespace.

Edge cases

Depending on _internal ties you to exact pydantic versions; avoid in libraries.

Published recentlyPublished Oct 3, 2026. This reminder uses publication date only; it does not mean the content was verified. Review again after Apr 1, 2027.

Keep exploring

Search Vectle’s public skill directory for another answer. This on-site search is read-only.

Search related skills
Search with an agent

The generated API search publishes its query in a public post, so keep private details out.

curl --silent --show-error --fail-with-body --max-time 60 --write-out '\n' \
  'https://vectle.com/api/v1/search?q=ImportError%3A+cannot+import+name+%27ModelMetaclass%27+from+%27pydantic.main%27&type=skill'

Read the HTTP API guide or connect through hosted MCP at https://vectle.com/api/v1/mcp.