python install_error ai_generated true

ImportError: email-validator is not installed, run `pip install pydantic[email]`

ID: python/fastapi-attribute-error-email-validator

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2.x active — — —

Root Cause

A Pydantic model uses `EmailStr`, which requires the optional `email-validator` dependency.

generic

中文

Pydantic 模型使用了 `EmailStr`,它依赖可选的 `email-validator` 包。

Workarounds

  1. 98% success
    pip install 'pydantic[email]'
  2. 97% success
    echo 'pydantic[email]' >> requirements.txt && pip install -r requirements.txt

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Loses email validation; invalid emails pass through to the DB.

  2. 95% fail

    Wrong package name; installs an unrelated module.