Forums

ImportError: No module named flask.ext.sqlalchemy

Now, I've seen quite a few similar problems to this already here, but I have attempted the solution. The following are logs:

2014-05-29 15:44:45,544 :Traceback (most recent call last):
2014-05-29 15:44:45,545 :  File "/bin/user_wsgi_wrapper.py", line 67, in __call__
2014-05-29 15:44:45,546 :    self.error_log_file.logger.exception("Error running WSGI application")
2014-05-29 15:44:45,546 :  File "/usr/lib/python3.3/logging/__init__.py", line 1269, in exception
2014-05-29 15:44:45,612 :    self.error(msg, *args, **kwargs)
2014-05-29 15:44:45,613 :  File "/usr/lib/python3.3/logging/__init__.py", line 1262, in error
2014-05-29 15:44:45,614 :    self._log(ERROR, msg, args, **kwargs)
2014-05-29 15:44:45,614 :  File "/usr/lib/python3.3/logging/__init__.py", line 1368, in _log
2014-05-29 15:44:45,615 :    self.handle(record)
2014-05-29 15:44:45,615 :  File "/usr/lib/python3.3/logging/__init__.py", line 1377, in handle
2014-05-29 15:44:45,616 :    if (not self.disabled) and self.filter(record):
2014-05-29 15:44:45,616 :  File "/usr/lib/python3.3/logging/__init__.py", line 687, in filter
2014-05-29 15:44:45,617 :    for f in self.filters:
2014-05-29 15:44:45,617 :  File "/bin/user_wsgi_wrapper.py", line 59, in __call__
2014-05-29 15:44:45,617 :    app_iterator = self.app(environ, start_response)
2014-05-29 15:44:45,618 :  File "/bin/user_wsgi_wrapper.py", line 73, in import_error_application
2014-05-29 15:44:45,618 :    raise e
2014-05-29 15:44:45,618 :  File "/bin/user_wsgi_wrapper.py", line 82, in <module>
2014-05-29 15:44:45,618 :    application = load_wsgi_application()
2014-05-29 15:44:45,619 :  File "/bin/user_wsgi_wrapper.py", line 78, in load_wsgi_application
2014-05-29 15:44:45,619 :    return __import__(os.environ['WSGI_MODULE'], globals(), locals(), ['application']).application
2014-05-29 15:44:45,619 :  File "/var/www/montgome_pythonanywhere_com_wsgi.py", line 16, in <module>
2014-05-29 15:44:45,621 :    from flask_app import app as application
2014-05-29 15:44:45,621 :  File "/home/montgome/mysite/flask_app.py", line 2, in <module>
2014-05-29 15:44:45,622 :    from flask.ext.sqlalchemy import SQLAlchemy
2014-05-29 15:44:45,622 :  File "/usr/local/lib/python3.3/dist-packages/flask/exthook.py", line 87, in load_module
2014-05-29 15:44:45,626 :    raise ImportError('No module named %s' % fullname)
2014-05-29 15:44:45,626 :ImportError: No module named flask.ext.sqlalchemy</blockquote>

Here's what I've used to install it:

19:18 ~/mysite/static $ pip3.3 install --user flask-sqlalchemy
Requirement already satisfied (use --upgrade to upgrade): flask-sqlalchemy in /home/montgome/.local/lib/python3.3/site-packages
Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/local/lib/python3.3/dist-packages/setuptools-3.4.4-py3.3.egg (from flask-sqlalchemy)
Requirement already satisfied (use --upgrade to upgrade): Flask>=0.10 in /usr/local/lib/python3.3/dist-packages (from flask-sqlalchemy)
Requirement already satisfied (use --upgrade to upgrade): SQLAlchemy in /usr/local/lib/python3.3/dist-packages (from flask-sqlalchemy)
Requirement already satisfied (use --upgrade to upgrade): Werkzeug>=0.7 in /usr/local/lib/python3.3/dist-packages (from Flask>=0.10->flask-sqlalchemy)
Requirement already satisfied (use --upgrade to upgrade): Jinja2>=2.4 in /usr/local/lib/python3.3/dist-packages (from Flask>=0.10->flask-sqlalchemy)
Requirement already satisfied (use --upgrade to upgrade): itsdangerous>=0.21 in /usr/local/lib/python3.3/dist-packages (from Flask>=0.10->flask-sqlalchemy)
Requirement already satisfied (use --upgrade to upgrade): markupsafe in /usr/local/lib/python3.3/dist-packages (from Jinja2>=2.4->Flask>=0.10->flask-sqlalchemy)
Cleaning up...

I am just confused as to what is the problem as it is clearly installed, as we can see here, too: 19:39 ~/mysite/static $ pip3.3 freeze | grep -i flask Flask==0.10.1 Flask-HTTPAuth==2.2.0 Flask-SQLAlchemy==1.0

Hopefully you can help with this!

Does this help?

http://stackoverflow.com/questions/18294680/aws-elastic-beanstalk-error-importerror-no-module-named-flask-ext-sqlalchemy

I think that the PythonAnywhere system Flask is not finding the SQLAlchemy extension (possibly because it only looks where it is installed). Try doing:

pip install --user flask

to get Flask into a local install and then see whether it finds the extension.

Hi, I am not sure whether the requirements.txts worked or not, but I definitely got it to work via local installations using pip install --user flask-sqlalchemy, and I also had to do it for login, for some reason.

I tried your setup (system install of Flask and user install of flask-sqlalchemy) and the import works fine fine. Are you messing with the Python path in your wsgi file? Have you restarted your web app since you installed flask-sqlalchemy?

I didn't mess with the Python path, I had gotten it to work! I was wondering if the fact that I had tried to use Python 3.3 & Flask 10.1 was the problem. I just set up with a new app, using 2.7 and 0.9 to get it going, and from there I cloned the flaskr example app (https://github.com/mitsuhiko/flask/tree/master/examples/flaskr/), which was initially giving me the problem w/ 3.3 and 10.1 and it set up perfectly. Thank you for all the help.