python install_error ai_generated true

pydantic.errors.PydanticUserError: `EmailStr` requires the `email-validator` package. Install it with `pip install pydantic[email]`.

ID: python/pydantic-email-str-deprecated

Also available as: JSON · Markdown · 中文
80%Fix Rate
90%Confidence
0Evidence
2024-01-18First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2.x active

Root Cause

EmailStr is used but the optional email-validator dependency is not installed.

generic

中文

使用了 EmailStr,但未安装可选的 email-validator 依赖。

Workarounds

  1. 98% success
    pip install 'pydantic[email]'
  2. 97% success
    pip install email-validator
    # then
    from pydantic import BaseModel, EmailStr
    class U(BaseModel):
        email: EmailStr

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Wrong package; 'email' is a stdlib module, not a PyPI validator.

  2. 55% fail

    Loses email format validation; invalid addresses pass through.

  3. 40% fail

    Import still fails until the interpreter restarts.