Forums

ImportError: No module named flask.ext.login

I've installed flask-login==0.2.7 and Flask-Security but it doesnt work :(

Error:

2014-03-10 17:14:32,679 :Traceback (most recent call last):
2014-03-10 17:14:32,679 :  File "/bin/user_wsgi_wrapper.py", line 67, in __call__
2014-03-10 17:14:32,680 :    self.error_log_file.logger.exception("Error running WSGI application")
2014-03-10 17:14:32,680 :  File "/usr/lib/python3.3/logging/__init__.py", line 1269, in exception
2014-03-10 17:14:32,681 :    self.error(msg, *args, **kwargs)
2014-03-10 17:14:32,681 :  File "/usr/lib/python3.3/logging/__init__.py", line 1262, in error
2014-03-10 17:14:32,682 :    self._log(ERROR, msg, args, **kwargs)
2014-03-10 17:14:32,682 :  File "/usr/lib/python3.3/logging/__init__.py", line 1368, in _log
2014-03-10 17:14:32,683 :    self.handle(record)
2014-03-10 17:14:32,683 :  File "/usr/lib/python3.3/logging/__init__.py", line 1377, in handle
2014-03-10 17:14:32,684 :    if (not self.disabled) and self.filter(record):
2014-03-10 17:14:32,684 :  File "/usr/lib/python3.3/logging/__init__.py", line 687, in filter
2014-03-10 17:14:32,685 :    for f in self.filters:
2014-03-10 17:14:32,685 :  File "/bin/user_wsgi_wrapper.py", line 59, in __call__
2014-03-10 17:14:32,685 :    app_iterator = self.app(environ, start_response)
2014-03-10 17:14:32,685 :  File "/bin/user_wsgi_wrapper.py", line 73, in import_error_application
2014-03-10 17:14:32,686 :    raise e
2014-03-10 17:14:32,686 :  File "/bin/user_wsgi_wrapper.py", line 67, in __call__
2014-03-10 17:14:32,686 :    self.error_log_file.logger.exception("Error running WSGI application")
2014-03-10 17:14:32,686 :  File "/usr/lib/python3.3/logging/__init__.py", line 1269, in exception
2014-03-10 17:14:32,687 :    self.error(msg, *args, **kwargs)
2014-03-10 17:14:32,687 :  File "/usr/lib/python3.3/logging/__init__.py", line 1262, in error
2014-03-10 17:14:32,688 :    self._log(ERROR, msg, args, **kwargs)
2014-03-10 17:14:32,688 :  File "/usr/lib/python3.3/logging/__init__.py", line 1368, in _log
2014-03-10 17:14:32,689 :    self.handle(record)
2014-03-10 17:14:32,689 :  File "/usr/lib/python3.3/logging/__init__.py", line 1377, in handle
2014-03-10 17:14:32,690 :    if (not self.disabled) and self.filter(record):
2014-03-10 17:14:32,690 :  File "/usr/lib/python3.3/logging/__init__.py", line 687, in filter
2014-03-10 17:14:32,691 :    for f in self.filters:
2014-03-10 17:14:32,691 :  File "/bin/user_wsgi_wrapper.py", line 59, in __call__
2014-03-10 17:14:32,692 :    app_iterator = self.app(environ, start_response)
2014-03-10 17:14:32,692 :  File "/bin/user_wsgi_wrapper.py", line 73, in import_error_application
2014-03-10 17:14:32,692 :    raise e
2014-03-10 17:14:32,692 :  File "/bin/user_wsgi_wrapper.py", line 82, in <module>
2014-03-10 17:14:32,692 :    application = load_wsgi_application()
2014-03-10 17:14:32,693 :  File "/bin/user_wsgi_wrapper.py", line 78, in load_wsgi_application
2014-03-10 17:14:32,693 :    return __import__(os.environ['WSGI_MODULE'], globals(), locals(), ['application']).application
2014-03-10 17:14:32,693 :  File "/var/www/rcham_pythonanywhere_com_wsgi.py", line 16, in <module>
2014-03-10 17:14:32,694 :    from addressbook.app import app as application
2014-03-10 17:14:32,694 :  File "/home/rcham/mysite/addressbook/app.py", line 6, in <module>
2014-03-10 17:14:32,695 :    from flask.ext.login import (LoginManager, current_user, login_required, \
2014-03-10 17:14:32,695 :  File "/usr/local/lib/python3.3/dist-packages/flask/exthook.py", line 87, in load_module
2014-03-10 17:14:32,695 :    raise ImportError('No module named %s' % fullname)
2014-03-10 17:14:32,695 :ImportError: No module named flask.ext.login

[edited by admin: formatting]

any ideas? :(

How did you install the packages? That is, was it with a virtualenv? Or with pip install --user?

Also, which version of Python are you using in the web app? Did you use the equivalent version of pip when installing the packages?

Ah, sorry, I can see that you're using Python 3 in the web app. So, did you use pip3.3 to install the packages?

pip3.3 install --user - r requirements.txt

OK, that sounds like it should have worked. What do you get if you run this in a bash console:

pip3.3 freeze | grep flask

...?

nothin comes up...

Ah, maybe there's a casing problem. Try this instead:

pip3.3 freeze | grep -i flask
Flask==0.10.1
Flask-HTTPAuth==2.2.0
Flask-SQLAlchemy==1.0
Flask-WTF==0.9.4

hmm my flask login isnt there...

[edited by admin: formatting]

Right, that sounds like the problem. It's strange that it's not there, but at least it not being there explains why you got an error in your web app! Could you try installing it again and post the output of the install command here?

17:58 ~ $ pip3.3 install flask-login
Downloading/unpacking flask-login
Downloading Flask-Login-0.2.10.tar.gz
Running setup.py (path:/tmp/pip_build_rcham/flask-login/setup.py) egg_info for package flask-login
Requirement already satisfied (use --upgrade to upgrade): Flask in /usr/local/lib/python3.3/dist-packages (from flas
k-login)
Requirement already satisfied (use --upgrade to upgrade): Werkzeug>=0.7 in /usr/local/lib/python3.3/dist-packages (f
rom Flask->flask-login)
Requirement already satisfied (use --upgrade to upgrade): Jinja2>=2.4 in ./.local/lib/python3.3/site-packages (from
Flask->flask-login)
Requirement already satisfied (use --upgrade to upgrade): itsdangerous>=0.21 in /usr/local/lib/python3.3/dist-packag
es (from Flask->flask-login)
Requirement already satisfied (use --upgrade to upgrade): markupsafe in /usr/local/lib/python3.3/dist-packages (from
Jinja2>=2.4->Flask->flask-login)
Installing collected packages: flask-login
Running setup.py install for flask-login
error: could not create '/usr/local/lib/python3.3/dist-packages/flask_login.py': Permission denied
Complete output from command /usr/local/bin/python3.3 -c "import setuptools, tokenize;__file__='/tmp/pip_build_r
cham/flask-login/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __fi
le__, 'exec'))" install --record /tmp/pip-1w209v-record/install-record.txt --single-version-externally-managed --com
pile:
running install
running build


running build_py


creating build


creating build/lib


copying flask_login.py -> build/lib


running install_lib


copying build/lib/flask_login.py -> /usr/local/lib/python3.3/dist-packages


error: could not create '/usr/local/lib/python3.3/dist-packages/flask_login.py': Permission denied


----------------------------------------
Cleaning up...
Command /usr/local/bin/python3.3 -c "import setuptools, tokenize;__file__='/tmp/pip_build_rcham/flask-login/setup.py
';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install -
-record /tmp/pip-1w209v-record/install-record.txt --single-version-externally-managed --compile failed with error co
de 1 in /tmp/pip_build_rcham/flask-login
Storing debug log for failure in /home/rcham/.pip/pip.log
18:01 ~ $

[edited by admin: formatting]

Looks like there is an error in installing but not sure what ive done wrong?

It looks like you missed out the --user flag in that pip install...

Doh! Of course! ahh sorry for your troubles...its always something simple...thanks for your help!

No problem! Is the web app OK now?

yes it is thanks! I've got some other debugging to do but that issue is fixed :)

Excellent! Thanks for confirming that, glad we could get it fixed :-)

I'm having a similar error, how should the command look?

If you're not using a virtualenv then it should be:

pip3.3 install --user flask-login

What if you are using virtualenv and still are getting an ImportError: No module named flask.ext.login

Well then you must install it into your virtualenv.

workon my-virtualenv-name
pip install flask-login