Forums

Having trouble importing flask_mail

Import section of code:

from flask import Flask, render_template,request,redirect,flash
from flask_wtf import Form
from wtforms import TextField, TextAreaField, validators
from wtforms.validators import DataRequired
from flask_mail import Message, Mail

Error logs below:

2016-06-14 13:35:18,238 :Error running WSGI application
    Traceback (most recent call last):
      File "/bin/user_wsgi_wrapper.py", line 154, in __call__
        app_iterator = self.app(environ, start_response)
      File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
        raise e
      File "/bin/user_wsgi_wrapper.py", line 154, in __call__
        app_iterator = self.app(environ, start_response)
      File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
        raise e
      File "/bin/user_wsgi_wrapper.py", line 154, in __call__
        app_iterator = self.app(environ, start_response)
      File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
        raise e
      File "/bin/user_wsgi_wrapper.py", line 179, in <module>
        application = load_wsgi_application()
      File "/bin/user_wsgi_wrapper.py", line 175, in load_wsgi_application
        return __import__(os.environ['WSGI_MODULE'], globals(), locals(), ['application']).application
      File "/var/www/fishingforyoungsters_pythonanywhere_com_wsgi.py", line 16, in <module>
        from flask_app import app as application
      File "/home/fishingforyoungsters/mysite/flask_app.py", line 3, in <module>
        from flask_mail import Message, Mail
    ImportError: No module named 'flask_mail'

I am not using a virtualenv, and running $ pip list shows Flask-Mail is installed.

What am I doing wrong?

Resolved this issue, I deleted the app and changed the python version fro 3.4 to 2.7

What output do you get from

pip2.7 show Flask-Mail

...?

It's working fine for me now, but here's the output incase you are asking for other reasons:

---
Metadata-Version: 2.0
Name: Flask-Mail
Version: 0.8.2
Summary: Flask extension for sending email
Home-page: https://github.com/rduplain/flask-mail
Author: Ron DuPlain
Author-email: ron.duplain@gmail.com
Installer: pip
License: BSD
Location: /usr/local/lib/python2.7/dist-packages
Requires: Flask, blinker
Classifiers:
  Development Status :: 4 - Beta
  Environment :: Web Environment
  Intended Audience :: Developers
  License :: OSI Approved :: BSD License
  Operating System :: OS Independent
  Programming Language :: Python
  Topic :: Internet :: WWW/HTTP :: Dynamic Content
  Topic :: Software Development :: Libraries :: Python Modules

Hmm, interesting -- it was a debugging step. Do you know what you did to make it work?

The app was running on python 3.4, I deleted the app from the web tab on the dashboard then recreated the app (with identical code) and chose to run it on python 2.7 this solved the problem though I'm not sure why.

Probably because you installed flask-mail for 2.7 and not 3.4.