Forums

ImportError: No module named flask.ext.security

My app works fine on my own machine and I have already installed flask-security, however, I get an import error when on the server.

Here is the import line from flask.ext.security import Security, SQLAlchemyUserDatastore, \ UserMixin, RoleMixin, login_required

If you simply do:

"import flask", is there an error?

Is it showing an error in your server logs? Can you post an example of the most recent traceback?

I'm having this problem. I have installed flask-security like so:

pip3.5 install --user flask-security==1.7.5

And I can see it:

17:14 ~/mysite $ pip3.5 freeze | grep -i flask
Flask==0.11.1
Flask-Admin==1.4.2
Flask-Babel==0.11.1
Flask-Bcrypt==0.7.1
Flask-Bootstrap==3.3.6.0
Flask-HTTPAuth==3.1.2
Flask-Login==0.3.2
Flask-Mail==0.9.1
Flask-Principal==0.4.0
Flask-RESTful==0.3.5
Flask-Script==2.0.5
Flask-Security==1.7.5
Flask-SQLAlchemy==2.1
Flask-WTF==0.12

But log says:

Error running WSGI application
ImportError: No module named flask.ext.security
File "/var/www/joegillon_pythonanywhere_com_wsgi.py", line 16, in <module>
from app import app as application

File "/home/joegillon/mysite/app.py", line 3, in <module>
from flask.ext.security import Security, SQLAlchemyUserDatastore, \

What's wrong?

Are you using a virtualenv for your web app? Is your web app configured to run Python 3.5?

Thanks for the response. No virtualenv. But the app is in 3.4. I didn't read the instructions closely enough. So just now I did pip3.4 install --user flask-security==1.7.5 and it said it installed but when I pip3.4 list I don't see it.

OK, I had previously installed flask-security with just "pip" and with "pip3.5". So, thinking magically, I uninstalled those and tried pip3.4 again and this time it worked. On to my next problem. Thanks for the help.