7

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).

sinoroc
  • 18,409
  • 2
  • 39
  • 70
Alexey Orlov
  • 2,412
  • 3
  • 27
  • 46
  • 1
    Run `poetry add 'pydantic[email]'` then look at the content of `pyproject.toml`. – sinoroc Aug 15 '21 at 10:02
  • 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 Aug 15 '21 at 10:29
  • 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 Aug 15 '21 at 11:22
  • Will you create an answer, so I could click on it? – Alexey Orlov Aug 15 '21 at 13:22
  • yeah, this is not a duplicate. your linked post is about providing extras, your question is about consuming them. – Arne Aug 16 '21 at 08:08

1 Answers1

17

Add something like the following in pyproject.toml:

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

or via the command line:

poetry add 'pydantic[email]'
sinoroc
  • 18,409
  • 2
  • 39
  • 70