Install email_validator using pip

Question:

I have email_validator installed but I am getting an error message saying it is not installed.
Does it have to be installed in my project folder? Or can it be in the main site-packages folder? When I run my program I get this error message:

Exception: Install 'email_validator' for email validation support

I can see that I have it installed in the main site-packages python3 folder, but when I run

pip install email_validator

from within my project folder site-packages folder the terminal prints this:

site-packages % pip install email_validator
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: email_validator in /Users/STL34/Library/Python/3.7/lib/python/site-packages (1.1.1)
Requirement already satisfied: idna>=2.0.0 in /Users/STL34/Library/Python/3.7/lib/python/site-packages (from email_validator) (2.10)
Requirement already satisfied: dnspython>=1.15.0 in /Users/STL34/Library/Python/3.7/lib/python/site-packages (from email_validator) (1.16.0)

And doesn’t install it in my project folder.

Here is the code:

from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField, BooleanField
from wtforms.validators import DataRequired, Length, Email, EqualTo


class RegistrationForm(FlaskForm):
    username = StringField('Username',
                           validators=[DataRequired(), Length(min=2, max=20)])
    email = StringField('Email',
                        validators=[DataRequired(), Email()])
    password = PasswordField('Password', validators=[DataRequired()])
    confirm_password = PasswordField('Confirm Password',
                                     validators=[DataRequired(), EqualTo('password')])
    submit = SubmitField('Sign Up')


class LoginForm(FlaskForm):
    email = StringField('Email',
                        validators=[DataRequired(), Email()])
    password = PasswordField('Password', validators=[DataRequired()])
    remember = BooleanField('Remember Me')
    submit = SubmitField('Login')

Asked By: STL34

||

Answers:

What do you mean by it doesn’t appear in my project. Could you post the output from doing

from email_validator import validate_email, EmailNotValidError

in our python file
If you are using pyenv then install that module from pyenv also.

Answered By: Dev-il

The simplest way to manage packages so there are no conflicts between projects and site packages are Virtual environments

email_validator example

sudo apt-get install -y python3-venv python3-pip
mkdir email
cd email
deactivate 2> /dev/null
pip3 show virtualenv
if [ $? -ne 0 ] ; then
   pip3 install --upgrade pip
   pip3 install --upgrade setuptools
   pip3 install virtualenv
fi

# now lets build venv
python3 -m venv venv
source venv/bin/activate
pip3 install email_validator
echo "import email_validator" > email.py
echo "print(email_validator.validate_email('[email protected]'))" >> email.py
python3 email.py

output

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-pip is already the newest version (20.0.2-5ubuntu1).
python3-venv is already the newest version (3.8.2-0ubuntu2).
0 upgraded, 0 newly installed, 0 to remove and 41 not upgraded.
Name: virtualenv
Version: 20.0.25
Summary: Virtual Python Environment builder
Home-page: https://virtualenv.pypa.io/
Author: Bernat Gabor
Author-email: [email protected]
License: MIT
Location: /home/mcs/.local/lib/python3.8/site-packages
Requires: distlib, appdirs, six, filelock
Required-by: 
Collecting email_validator
  Using cached email_validator-1.1.1-py2.py3-none-any.whl (17 kB)
Collecting idna>=2.0.0
  Using cached idna-2.10-py2.py3-none-any.whl (58 kB)
Collecting dnspython>=1.15.0
  Using cached dnspython-1.16.0-py2.py3-none-any.whl (188 kB)
Installing collected packages: idna, dnspython, email-validator
Successfully installed dnspython-1.16.0 email-validator-1.1.1 idna-2.10
<ValidatedEmail [email protected]>
Answered By: Rob Raymond

I resolved the issue. I used pip with a -t flag to install email_validator in my project folder site packages folder. Without the -t flag pip installs email_validator in the Python3 site-packages folder and that doesn’t work.

Answered By: STL34

To resolve this issue with WTForms v3.0.1 package you need to run:

pip install wtforms[email]
Answered By: Freddie von Stange

I am having a similar issue right now.

I tried both:

pip install wtforms[email]

and

pip install email_validator

Both come back with:

Requirement already satisfied: ...

And yet still every time I run the program I get:

Traceback (most recent call last):


File "D:Code100daysday61_flask-WTFmain.py", line 9, in <module>
    class SignInForm(Form):
  File "D:Code100daysday61_flask-WTFmain.py", line 10, in SignInForm
    email = StringField(label='email', validators=[DataRequired(), Email()])
                                                                   ^^^^^^^
  File "D:Code100daysday61_flask-WTFvenvLibsite-packageswtformsvalidators.py", line 393, in __init__
    raise Exception("Install 'email_validator' for email validation support.")
Exception: Install 'email_validator' for email validation support.

I don`t understand why is this happenning…

Answered By: 87lst