flask_mail似乎是在pythonanywhere中导入的,但是在运行时会得到错误代码:无模块命名

时间:2019-12-02 11:24:40

标签: flask pythonanywhere flask-mail

我正在尝试通过flask_mail通过电子邮件发送pandas DataFrame:

from flask import Flask, redirect, render_template, request, url_for, jsonify, session
from flask_mail import Mail, Message
app.config['MAIL_SERVER'] = 'smtp.****.com'
app.config['MAIL_PORT'] = ***
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = '****'
app.config['MAIL_PASSWORD'] = '***'
mail = Mail(app)

@app.route("/sent", methods=["GET", "POST"])
def sent():
    recipient = str(request.form["email"])
    df_*** = pd.read_msgpack(session['***'])
    df_client = pd.read_msgpack(session['client'])
    msg = Message("Thank you for your interest!",
                    sender="***@***.com",
                    recipients = [recipient])
    msg.html = df_client.to_html()
    msg_*** = Message("A new calculation was made by {{email}}",
                sender="***@***.com",
                recipients = ["***@***.com"])
    msg_***.html = df_***.to_html()
    return "Thank you for showing interest!"

但是,我继续遇到相同的错误:

2019-12-02 11:08:34,919: Error running WSGI application
2019-12-02 11:08:34,920: ModuleNotFoundError: No module named 'flask_mail'
2019-12-02 11:08:34,920:   File "/var/www/****_pythonanywhere_com_wsgi.py", line 16, in <module>
2019-12-02 11:08:34,920:     from flask_app import app as application  # noqa
2019-12-02 11:08:34,920: 
2019-12-02 11:08:34,920:   File "/home/****/mysite/flask_app.py", line 2, in <module>
2019-12-02 11:08:34,921:     from flask_mail import Mail, Message
2019-12-02 11:08:34,921: ***************************************************
2019-12-02 11:08:34,921: If you're seeing an import error and don't know why,
2019-12-02 11:08:34,921: we have a dedicated help page to help you debug: 
2019-12-02 11:08:34,921: https://help.pythonanywhere.com/pages/DebuggingImportError/
2019-12-02 11:08:34,921: ***************************************************

但是,当我导入flask_mail时,我的代码中没有得到错误标签,或者当我尝试进行pip安装时,它似乎已经安装了:

10:45 ~/mysite $ pip install flask_mail
Looking in links: /usr/share/pip-wheels
Requirement already satisfied: flask_mail in /usr/local/lib/python2.7/dist-packages (0.9.1)
Requirement already satisfied: Flask in /usr/local/lib/python2.7/dist-packages (from flask_mail) (1.0.2)
Requirement already satisfied: blinker in /usr/local/lib/python2.7/dist-packages (from flask_mail) (1.4)
Requirement already satisfied: Jinja2>=2.10 in /usr/local/lib/python2.7/dist-packages (from Flask->flask_mail) (2.10)
Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python2.7/dist-packages (from Flask->flask_mail) (0.24)
Requirement already satisfied: Werkzeug>=0.14 in /usr/local/lib/python2.7/dist-packages (from Flask->flask_mail) (0.14.1)
Requirement already satisfied: blinker in /usr/local/lib/python2.7/dist-packages (from flask_mail) (1.4)
Requirement already satisfied: click>=5.1 in /usr/local/lib/python2.7/dist-packages (from Flask->flask_mail) (6.7)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python2.7/dist-packages (from Jinja2>=2.10->Flask->flask_mail) (1.0)
10:45 ~/mysite $ pip install Flask-Mail
Looking in links: /usr/share/pip-wheels
Requirement already satisfied: Flask-Mail in /usr/local/lib/python2.7/dist-packages (0.9.1)
Requirement already satisfied: Flask in /usr/local/lib/python2.7/dist-packages (from Flask-Mail) (1.0.2)
Requirement already satisfied: blinker in /usr/local/lib/python2.7/dist-packages (from Flask-Mail) (1.4)
Requirement already satisfied: Jinja2>=2.10 in /usr/local/lib/python2.7/dist-packages (from Flask->Flask-Mail) (2.10)
Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python2.7/dist-packages (from Flask->Flask-Mail) (0.24)
Requirement already satisfied: Werkzeug>=0.14 in /usr/local/lib/python2.7/dist-packages (from Flask->Flask-Mail) (0.14.1)
Requirement already satisfied: click>=5.1 in /usr/local/lib/python2.7/dist-packages (from Flask->Flask-Mail) (6.7)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python2.7/dist-packages (from Jinja2>=2.10->Flask->Flask-Mail) (1.0)

1 个答案:

答案 0 :(得分:2)

已解决。我显然使用的是3.6,而不是3.7。因此pip3.6 install --user Flask-Mail解决了这个问题。