FastAPI

背景

from pydantic import BaseModel, EmailStr

class UserIn(BaseModel):
    username: str
    password: str
    email: EmailStr
    full_name: Optional[str] = None

定义的 Pydantic Model 某个字段声明为 EmailStr 类型

运行 uvicorn 服务器的时候报错

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

根因

缺少 email_validator 库

解决方法

pip install email_validator

注意

虽然它提示了解决方法,但很大可能会提示你

> pip install pydantic[email]  
zsh: no matches found: pydantic[email]
原文地址:https://www.cnblogs.com/poloyy/p/15317410.html