4

After activating my venv and installing Pydantic through

pip install pydantic

I tried creating a new file as follows:

from pydantic import Basemodel, EmailStr

class Person(BaseModel):
      id: int
      name: str
      email: EmailStr

and was just running this file with the unused class. But it returned the following error:

ModuleNotFoundError: No module named 'email_validator'
.
.
.
ImportError: email-validator is not installed, run `pip install pydantic[email]`

When running the hint

pip install pydantic[email]

it tells me:

zsh: no matches found: pydantic[email]

Could someone help me with this stupid beginner error? Thanks!

I reinstalled Pydantic, recreated a venv, reactivated the venv.

Daniil Fajnberg
  • 12,753
  • 2
  • 10
  • 41
jonsdope
  • 51
  • 1
  • 3
  • 1
    sorry not your fault but people have already encountered this pip-on-zsh issue before so looks like a duplicate. hopefully that fixed your issue though. welcome aboard. – JL Peyret Jan 05 '23 at 19:54

1 Answers1

10

This has nothing to do with Python, Pydantic, or your virtual environment. It tells you that this is a shell error by starting the error message with your shell's name zsh.

When you write ... pydantic[email], zsh interprets this as a glob pattern to match files named pydantic followed by either e, m, a, i, or l. It finds no files matching that pattern in your working directory and gives you that error.

To avoid this, you can simply put that argument in quotes like this:

pip install 'pydantic[email]'
Daniil Fajnberg
  • 12,753
  • 2
  • 10
  • 41