1
votes

This is a duplicate, I know. Nothing helps, however. I just want the 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).

1
Run poetry add 'pydantic[email]' then look at the content of pyproject.toml. - sinoroc
Yes, it's just pydantic = {extras = ["email"], version = "^1.8.2"}. And it works. It looks like I tried it too, manually :) . [tool.poetry.extras] section is not needed any more? - Alexey Orlov
The section [tool.poetry.extras] in combination with optional = true is if your project (library or application) has "extras" itself. So in your case, you don't need those. - sinoroc
Will you create an answer, so I could click on it? - Alexey Orlov
yeah, this is not a duplicate. your linked post is about providing extras, your question is about consuming them. - Arne

1 Answers

2
votes

Add something like the following in pyproject.toml:

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

or via the command line:

poetry add 'pydantic[email]'