3

I have tried both

from flask.ext.sqlalchemy import SQLAlchemy

and

from flask_sqlalchemy import SQLAlchemy

inside flask/esk I only have a __init__.py and a __init__.pyc, and inside flask_sqlalchemy I only have _compat.py, _coompat.pyc, __init__.py and __init__.pyc. Should I copy the SQLAlchemy package in to one of these directories? I read here that ext is deprected so I'm unsure.

stack-overflow deprected flask ext

I'm getting these errors

ImportError: No module named flask_sqlalchemy

and

ImportError: No module named flask.ext.sqlalchemy

I installed with pip

4
  • How did you install Flask-SQLAlchemy? Commented Nov 10, 2015 at 13:17
  • I used sudo pip, it was in a virtual env but i've also tried on my main machine. Commented Nov 10, 2015 at 13:25
  • Pip will install a library's dependencies, so SQLAlchemy should be there, too. Please update your answer with the exact error you're getting. Commented Nov 10, 2015 at 13:27
  • Yeah I know they should be there. Commented Nov 10, 2015 at 13:35

1 Answer 1

5

Flask-SQLAlchemy doesn't come with Flask. You need to install it. You are correct, flask.ext is deprecated, but all it is is a "shortcut" for accessing other installed packages that are Flask extensions. Since you haven't installed Flask-SQLAlchemy, you can't import it.

$ pip install flask-sqlalchemy

It is bad practice to manually install libraries to the system Python location (sudo pip). Use a virtualenv.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.