WTForms: Install 'email_validator' for email validation support
PythonFlaskWtformsPython Problem Overview
Getting exception when running the following code for form validation.
File "/Users/homeduvvuri/Documents/Learning/PartyGoUdemy/PartGo/user/forms.py", line 11, in BaseUserForm
email = EmailField('Email', [validators.DataRequired(), validators.Email()])
File "/Users/homeduvvuri/Documents/Learning/PartyGoUdemy/PartGo/partgo-env/lib/python3.7/site-packages/wtforms/validators.py", line 332, in __init__
raise Exception("Install 'email_validator' for email validation support.")
Exception: Install 'email_validator' for email validation support.
Runs perfectly on codeanywhere VM. Does not on local machine.
from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileAllowed
from wtforms import Form, StringField, PasswordField, validators, ValidationError
from wtforms.validators import InputRequired, Email
from wtforms.fields.html5 import EmailField
from wtforms.widgets import TextArea
from user.models import User
class BaseUserForm(FlaskForm):
name = StringField('Name', [validators.DataRequired(), validators.Length(min=2, max=30)])
email = EmailField('Email', [validators.DataRequired(), validators.Email()])
Python Solutions
Solution 1 - Python
If you take a look at wtforms/validators.py file in line 9:
import email_validator
Just install the package:
pip install email_validator
Solution 2 - Python
If you want it installed with wtforms
:
pip install wtforms[email]
Solution 3 - Python
From WTForms 2.3.0 version, the email validation is handled by an external library called email-validator
(PR #429). If you want to enable email validation support, you either need to install WTForms with extra requires email
:
$ pip install wtforms[email]
Or you can install email-validator
directly:
$ pip install email-validator
Or you can back to the old version of WTForms:
$ pip install wtforms==2.2.1
P.S. If you are using Flask-WTF, except for install email-validator
directly, you can also use email
extra (if PR #423 got merged) in the next release (> 0.14.3).
Solution 4 - Python
Try install
pip install email-validator
Solution 5 - Python
This happened to me as well when i run it using virtual env. anaconda 3.7 However when i switched my project interpreter back to my local machine Python 3.7, then i run:
pip install email_validator
it worked fine.
I just found it strange that I couldn't install the module "email_validator" in my anaconda Project Interpreter. So i suggest that you try with local machine first.
Solution 6 - Python
I had the same problem with the latest updates, tried to install email_validator and flask-validator and continued with this exception. Solved by adding in requirements.txt the following line: email-validator == 1.0.5 as suggested [here].(https://github.com/alphagov/notifications-admin/commit/5ce2906c5aa6d16)
Actually wtforms[email]==2.3.1 is what I need.
Solution 7 - Python
you need pip install email-validator
, wtforms depend on email-validator.
you can see email-validator module on Github https://github.com/JoshData/python-email-validator
Solution 8 - Python
This should work as it worked for me. Just install this in project terminal:
pip install email-validator
Solution 9 - Python
Try install
pip install WTForms==2.1
Solution 10 - Python
Adding to what is already said for future referance,
pip install email_validator
P.S You dont need to import email_validator after installing.
Solution 11 - Python
from wtf forms
> Validates an email address. Requires email_validator package to be installed. For ex: pip install wtforms[email].
pip install wtforms[email]
pip install email_validator
Solution 12 - Python
Inside wtforms/validators.py
file, line 392, you can see that there is exception handling for this occurrence in particular, which is why the following lines are executed to throw the alert
if email_validator is None: # pragma: no cover
raise Exception("Install 'email_validator' for email validation
support.")
Solution is to pip install email-validator
in the same location/directory for wtforms/validators.py sake.
I had the same error before:(
Solution 13 - Python
In your project directory run:
pip install email_validator
This worked for me!
Solution 14 - Python
I don't know if the root cause was that I used zsh in Terminal but I also get the error "zsh: no matches found: wtforms[email]" when I tried the command below.
pip install wtforms[email]
However, I tried to do the following command, it worked for me.
pip install -U "wtforms[email]"
Solution 15 - Python
If we use wtforms.validators.Email in our python program, then it raise an exception that asks us to install the email_validator for email validation support. The solution for that problem is to type the following command in terminal pip install email_validator
Solution 16 - Python
If you have removed build dependencies before running your app, please check whether idna
exists.
For Alpine Linux, use apk add py3-idna
before installing build dependencies. Then this package will not be in the build dependency virtual package so will not be removed automatically.