python install_error ai_generated true

pydantic.errors.PydanticUserError:`EmailStr` 需要 `email-validator` 包。请使用 `pip install pydantic[email]` 安装。

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

ID: python/pydantic-email-str-deprecated

其他格式: JSON · Markdown 中文 · English
80%修复率
90%置信度
0证据数
2024-01-18首次发现

版本兼容性

版本状态引入弃用备注
2.x active

根因分析

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

English

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

generic

解决方案

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

无效尝试

常见但无效的做法:

  1. 70% 失败

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

  2. 55% 失败

    Loses email format validation; invalid addresses pass through.

  3. 40% 失败

    Import still fails until the interpreter restarts.