ImportError: cannot import name 'BaseSettings' (or ModelMetaclass, field_validator, any name) from 'pydantic...': which pydantic releases have it
pydantic 2.0 (2023-06-30) moved BaseSettings to the separate pydantic-settings package and removed 197 names, which now raise PydanticImportError; 1.10.27 is the last 1.x. Fix the first with pip install pydantic-settings and from pydantic_settings import BaseSettings. For the others, either move to the 2.x API (table below) or import the old name from pydantic.v1, which carries the whole 1.x API in every 2.x release (and, as an alias, in 1.10.15 and later). validator and root_validator still import in 2.14.4, with a deprecation warning. For any other name, paste the error below.
Corrected on 2026-12-05: this page read only the first release of each minor version, so a name added or removed in a patch release was dated to the next minor. For example, the lookup said the module pydantic.v1 exists from 2.0; it is also in 1.10.15 (2024-04-03) and every later 1.10.x. And from pydantic import AnyWebsocketUrl works from 2.7.1 (2024-04-23), not only from 2.8.0. Every release was then read once from PyPI: 35 top-level names (and 1,542 module-and-name pairs in all) differ in some patch release from the first release of the same minor. The lookup now gives those patch releases. The per-minor ranges are unchanged.
Examples:
Runs in your browser on pydantic.json (217 KB) and 165 KB of hints in this page; nothing you paste is sent anywhere. Covers 6,432 module-and-name pairs in 114 modules.
What replaces the 1.x names in 2.x?
| 1.x | 2.x |
|---|---|
BaseSettings | pip install pydantic-settings; from pydantic_settings import BaseSettings |
| validator, root_validator (still import, deprecated) | field_validator, model_validator |
| class Config: inside a model | model_config = ConfigDict(...) |
| parse_obj_as, schema_of (still import, deprecated) | TypeAdapter(T).validate_python(...), .json_schema() |
pydantic.main.ModelMetaclass | private: pydantic._internal._model_construction.ModelMetaclass |
pydantic.fields.ModelField | pydantic.fields.FieldInfo, Model.model_fields |
| Required, ConstrainedStr, constr-style classes, stricturl, parse_raw_as and 190 more | raise PydanticImportError; pydantic.v1 keeps them |
PyObject | ImportString (redirected with a warning from 2.1.0) |
pydantic.generics.GenericModel | BaseModel with Generic[T] (redirected with a warning from 2.1.0) |
Moved names are listed in pydantic/_migration.py: 30 of them still import from the old place in 2.14.4 and warn (for example pydantic.utils.deep_update, served from pydantic.v1.utils); the 197 removed ones raise. The lookup counts the first group as importable and gives the message for the second.
How was this read, and how was it checked?
From the Python files at the release tags of pydantic/pydantic (the first release of every minor, plus the latest), parsed with Python's ast module. The tags match the wheels on PyPI (every .py file compared by git blob hash at 1.10.0, 2.0, 2.7.0 and 2.14.4). A module's names are everything it binds at module level, what from .x import * brings in, the names of the lazy-import table that pydantic/__init__.py serves through __getattr__ from 2.0, and the moved names of the migration table in each module that installs getattr_migration.
Checks: (1) the top-level names are found as plain text in pydantic/__init__.py (or its migration table) in every release of their range (7,988 name-and-release pairs) and are not bound on either side (443 edges). (2) A regular expression finds 19,496 definitions in 1,219 file versions; all are among the names read. (3) 19 release checks by text search in the tagged files agree:
| Name | Release | Text and data |
|---|---|---|
pydantic.BaseSettings | 1.10.0 | importable |
pydantic.BaseSettings | 2.0 | not importable |
pydantic.main.ModelMetaclass | 1.10.0 | importable |
pydantic.main.ModelMetaclass | 2.0 | not importable |
pydantic.field_validator | 1.10.0 | not importable |
pydantic.field_validator | 2.0 | importable |
pydantic.ConfigDict | 1.9.0 | not importable |
pydantic.ConfigDict | 1.10.0 | importable |
pydantic.TypeAdapter | 2.0 | importable |
pydantic.utils.deep_update | 2.0 | importable |
pydantic.Required | 1.10.0 | importable |
pydantic.Required | 2.0 | not importable |
pydantic.with_config | 2.6.0 | not importable |
pydantic.with_config | 2.7.0 | importable |
pydantic.generics.GenericModel | 2.0 | not importable |
pydantic.generics.GenericModel | 2.1.0 | importable |
pydantic.v1.BaseModel | 2.0 | importable |
pydantic.v1 | 1.10.14 | not importable (text only) |
pydantic.v1 | 1.10.15 | importable (text only) |
Limits
- Nothing was installed or run. "Has it" means the import statement resolves in the Python files of that release.
- The ranges use the first release of each minor version. Every release was also read once (173 releases, from the files on PyPI, with the same rules): 35 top-level names and 1,542 module-and-name pairs in all differ in some patch release from the first release of their minor (all 0.0.x releases count as one minor here). The lookup prints those patch releases under the range. pydantic-settings and pydantic-core are not covered.
Questions
How do I fix "cannot import name 'BaseSettings' from 'pydantic'"?
pydantic 2.0 (2023-06-30) moved it to its own package: pip install pydantic-settings, then from pydantic_settings import BaseSettings. In 2.x the error is PydanticImportError: "`BaseSettings` has been moved to the `pydantic-settings` package." To keep old code unchanged, pin pip install "pydantic<2" (1.10.27 is the last 1.x).
What does "PydanticImportError: `pydantic:Required` has been removed in V2" mean?
197 names (in 2.14.4) are listed in pydantic's migration table as removed; importing one raises this error. Each has a 2.x replacement (Required becomes a field without a default, ConstrainedStr becomes Annotated[str, StringConstraints(...)], parse_raw_as becomes TypeAdapter(T).validate_json). To keep the 1.x behaviour, import it from pydantic.v1, which carries the whole 1.x API from 2.0 on.
How do I fix "cannot import name 'ModelMetaclass' from 'pydantic.main'"?
pydantic 2.0 moved the metaclass to the private module pydantic._internal._model_construction. Code that needs it on 2.x imports it from there (it can change without notice); code written for 1.x can use from pydantic.v1.main import ModelMetaclass.
How do I fix "cannot import name 'field_validator' from 'pydantic'"?
You have pydantic 1.x: field_validator, model_validator, TypeAdapter and computed_field are new in 2.0. pip install "pydantic>=2", or keep validator and root_validator, which work in both.
Can one codebase import from pydantic.v1 on both 1.x and 2.x?
Yes, from pydantic 1.10.15: that release added a pydantic.v1 module that aliases the 1.x namespace, so from pydantic.v1 import BaseModel works on 1.10.15 and later and on every 2.x.
Sources
- pydantic/pydantic: pydantic/_migration.py at v2.14.4 (the moved and removed names and the messages), pydantic/v1.py at v1.10.15, and the release tags.
- pydantic on PyPI (release dates, and the wheels compared with the tags) and pydantic-settings.
The same data as JSON: pydantic.json, licensed CC BY 4.0.
Related: "cannot import name ... from 'langchain'" · "... from 'openai'" · "... from 'llama_index'".