Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python poetry, install optional dependencies

I just want the poetry equivalent of this:

$ pip install pydantic[email]

I've read all the relevant posts. Now my pyproject.toml looks like this (I tried everything else, too):

[tool.poetry.dependencies]
pydantic = {version = "*", optional = true, extras = ["email"]}
...

[tool.poetry.extras]
email = ["pydantic"]

I also removed .venv, and poetry.lock, then $ poetry install. No use. The runtime error is clear:

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

I can add one detail: pydantic itself is a dependency (it was absent from pyproject.toml before I ran into this problem).

like image 265
Alexey Orlov Avatar asked Apr 17 '26 16:04

Alexey Orlov


1 Answers

Add something like the following in pyproject.toml:

[tool.poetry.dependencies]
pydantic = {version = "*", extras = ["email"]}

and then run:

poetry install

or directly via this command:

poetry add 'pydantic[email]'
like image 100
sinoroc Avatar answered Apr 20 '26 23:04

sinoroc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!