问题
from flask_mail import Mail,Message
from flask import Flask
I am trying to mail but import error is occurring
回答1:
The are two packages by that name:
The project found on GitHub and in PyPI uses
flask_mail
as the package name; see their documentation and project source code.Their layout indeed requires:
from flask_mail import Mail, Message
This is a fork of the other project, but is currently actively maintained.
There is a project on Bitbucket, and their Flask-Mail documentation and the project source code show that the correct import is:
from flaskext.mail import Mail, Message
This project appears to be outdated and has not seen an update for almost 3 years now. The Github project names the same original author, it appears to be an updated fork. I'd stick with the Github project.
If neither works, then there is no such module installed, not in the location that the Python version running your Flask server can find.
回答2:
You have to install flask_mail in order to be able to import it. if you are working with linux type this into your terminal and hit enter: $ sudo pip install flask_mail
来源:https://stackoverflow.com/questions/24585913/importerror-no-module-named-flask-mail