flask_mail 似乎是在 pythonanywhere 中导入的,但是运行时出现错误代码 : no module named

标签 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 install时,它似乎已经安装了:

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)

最佳答案

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

关于flask_mail 似乎是在 pythonanywhere 中导入的,但是运行时出现错误代码 : no module named,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59137938/

相关文章:

python - 如何在 Flask-RESTful 中添加自定义 HTTP 响应 header ?

javascript - 如何使用 Flask 和 jQuery 显示/隐藏回复文本框?

python - 如何在 pythonanywhere 上安装 GNU MPFR 库

python - Flask 蓝图与 gevent 在应用程序上下文之外工作

python - 配置 Flask-Mail 以使用 GMail

python - 为什么这个 Python Flask 路由器在被跨域 AJAX 调用 ping 时返回 400 错误?

http-headers - 在 flask 中获取客户端IP地址

mysql - 错误 1044 在 pythonanywhere 上的 mysql 中创建触发器

makefile - 在没有 apt-get 的情况下在 pythonanywhere 中从源代码安装

flask - 使用 Flask-Mail 发送邮件时连接被拒绝