New to flask and Flask-Login – ImportError: No module named login
Question:
It appears that installation of flask-login has issues. Despite a successful install using the below
pip install flask-login
My app.py file:
from flaskext.login import LoginManager
lm = LoginManager()
I get this error :
ImportError: No module named login
So how do I resolve
Answers:
There was a transition of the flask extension import way:
Instead we now recommend naming packages flask_foo
instead of the now deprecated flaskext.foo
. Flask 0.8 introduces a redirect import system that lets uses import from flask.ext.foo
and it will try flask_foo
first and if that fails flaskext.foo
.
Flask extensions should urge users to import from flask.ext.foo
instead of flask_foo or flaskext_foo so that extensions can transition to the new package name without affecting users. (Source)
Use this import way with Flask 0.8 or later:
from flask.ext.login import LoginManager
sudo pip install Flask-Security
For flask-login 0.3.2 and later, following is the way:
from flask_login import LoginManager
to find the flask-login version, you can run the following command in terminal. Just change the name to know the version of other packages.
pip show flask-login
Note:- not sure from which version of flask-login this convention is followed
There was yet another transition of the way Flask extensions are imported.
The Flask 0.8 style from flask.ext.login import …
is no longer supported, and the even earlier style from flaskext.login import …
is also no longer supported.
Use this way with Flask 1.0 or later:
from flask_login import LoginManager
Use this for importing LoginManager
from flask_login import LoginManager
Login = LoginManager()
Flask login tutorial
https://learnpyjs.blogspot.com/2021/02/how-to-setup-user-login-in-flask.html?m=1
If you have flask (and flask_login) installed already and getting ModuleNotFoundError: No module named 'flask_login'
just do
sudo pip install flask
or for python3 sudo pip3 install flask
Adding sudo
solved this issue for me
It appears that installation of flask-login has issues. Despite a successful install using the below
pip install flask-login
My app.py file:
from flaskext.login import LoginManager
lm = LoginManager()
I get this error :
ImportError: No module named login
So how do I resolve
There was a transition of the flask extension import way:
Instead we now recommend naming packages
flask_foo
instead of the now deprecatedflaskext.foo
. Flask 0.8 introduces a redirect import system that lets uses import fromflask.ext.foo
and it will tryflask_foo
first and if that failsflaskext.foo
.Flask extensions should urge users to import from
flask.ext.foo
instead of flask_foo or flaskext_foo so that extensions can transition to the new package name without affecting users. (Source)
Use this import way with Flask 0.8 or later:
from flask.ext.login import LoginManager
sudo pip install Flask-Security
For flask-login 0.3.2 and later, following is the way:
from flask_login import LoginManager
to find the flask-login version, you can run the following command in terminal. Just change the name to know the version of other packages.
pip show flask-login
Note:- not sure from which version of flask-login this convention is followed
There was yet another transition of the way Flask extensions are imported.
The Flask 0.8 style from flask.ext.login import …
is no longer supported, and the even earlier style from flaskext.login import …
is also no longer supported.
Use this way with Flask 1.0 or later:
from flask_login import LoginManager
Use this for importing LoginManager
from flask_login import LoginManager
Login = LoginManager()
Flask login tutorial
https://learnpyjs.blogspot.com/2021/02/how-to-setup-user-login-in-flask.html?m=1
If you have flask (and flask_login) installed already and getting ModuleNotFoundError: No module named 'flask_login'
just do
sudo pip install flask
or for python3 sudo pip3 install flask
Adding sudo
solved this issue for me