我已经安装了email_validator,但是却收到一条错误消息,提示未安装。 是否必须将其安装在我的项目文件夹中?还是可以在主站点包文件夹中?当我运行程序时,出现以下错误消息:
Exception: Install 'email_validator' for email validation support
我可以看到我已经将其安装在主站点包python3文件夹中,但是当我运行时
pip install email_validator
在我的项目文件夹site-packages文件夹中,终端显示以下内容:
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)
并且不将其安装在我的项目文件夹中。
代码如下:
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')
答案 0 :(得分:2)
email_validator示例
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('hello@gmail.com'))" >> email.py
python3 email.py
输出
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: gaborjbernat@gmail.com
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 hello@gmail.com>
答案 1 :(得分:0)
您的意思是它没有出现在我的项目中。你能发布输出结果吗
from email_validator import validate_email, EmailNotValidError
在我们的python文件中
如果您使用的是pyenv
,则也可以从pyenv
安装该模块。
答案 2 :(得分:0)
我解决了这个问题。我使用带有-t标志的pip在我的项目文件夹站点包文件夹中安装email_validator。如果没有-t标志,则pip会在Python3 site-packages文件夹中安装email_validator,这是行不通的。