跳到内容

安装

安装非常简单,只需

pip install pydantic
uv add pydantic

Pydantic 有一些依赖项

如果您安装了 Python 3.9+ 和 pip,就可以开始了。

Pydantic 也可在 conda 上通过 conda-forge 频道获取

conda install pydantic -c conda-forge

可选依赖项

Pydantic 具有以下可选依赖项

  • email: 由 email-validator 包提供的电子邮件验证。
  • timezone: 由 tzdata 包提供的备用 IANA 时区数据库。

要安装可选依赖项以及 Pydantic

# with the `email` extra:
pip install 'pydantic[email]'
# or with `email` and `timezone` extras:
pip install 'pydantic[email,timezone]'
# with the `email` extra:
uv add 'pydantic[email]'
# or with `email` and `timezone` extras:
uv add 'pydantic[email,timezone]'

当然,您也可以使用 pip install email-validator tzdata 手动安装需求。

从仓库安装

如果您希望直接从仓库安装 Pydantic

pip install 'git+https://github.com/pydantic/pydantic@main'
# or with `email` and `timezone` extras:
pip install 'git+https://github.com/pydantic/pydantic@main#egg=pydantic[email,timezone]'
uv add 'git+https://github.com/pydantic/pydantic@main'
# or with `email` and `timezone` extras:
uv add 'git+https://github.com/pydantic/pydantic@main#egg=pydantic[email,timezone]'