34

I have a problem with flask_login module.

i have installed flask_login module successfully. Also from the command prompt i can run this script easily with no error:

Python 2.7 (r27:82525, Jul  4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from flask.ext.login import LoginManager

But when I am running this script:

from flask import Flask
from flask.ext.login import LoginManager
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World! Welcome"

if __name__ == "__main__":
    app.run()

i am getting the error :

ImportError: No module named flask.ext.login

What is the mistake i am doing. I am very new to this flask. Thanks in advance.

curiousguy
  • 2,694
  • 6
  • 31
  • 55
  • 7
    How are you running the script? How was `flask_login` installed? – Martijn Pieters Feb 11 '14 at 11:58
  • 2
    Random guesses: Wrong Python interpreter? Virtualenv? – dav1d Feb 11 '14 at 11:59
  • I am not using Virtualenv , I have installed flask separately with all the dependency modules.Actually I am just testing if the set up is fine or not. I tried via virtualenv but i am getting some error. So tried to installed everything separately. The piece of code works fine until I have added `from flask.ext.login import LoginManager`. – curiousguy Feb 11 '14 at 12:01
  • I installed flask_login from `https://pypi.python.org/` site – curiousguy Feb 11 '14 at 12:04
  • You are right @Martijn Pieters asking `How are you running the script?` – curiousguy Feb 11 '14 at 12:39
  • Your question was asked and answered here: http://stackoverflow.com/questions/13065682/how-to-manually-install-flask-extensions/13077029#13077029 – MatrixMummy Mar 20 '17 at 04:45

8 Answers8

39

If following does not work:

from flask.ext.login import LoginManager

try the following:

from flask_login import LoginManager

This is the new convention.

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
prem kumar
  • 4,631
  • 2
  • 20
  • 32
  • I had this problem with Flask-session. Direct from the docs - `from flask.ext.session import Session`. This solution solved that problem too. `from flask_session import Session` – Mote Zart Dec 28 '19 at 21:55
  • I had the same thing with `from flask.ext.scss import Scss` and used `from flask_scss import Scss` instead and it solved it. I'm using Pythonista on iPad. – eallenOP Jan 15 '20 at 22:31
14

Install pip and then use the following command:

C:\Python27\scripts>pip install Flask-Login

Najeebullah Shah
  • 4,124
  • 3
  • 33
  • 46
9

If you have already installed flask-login by

$pip install flask_login

Try replacing the

from flask.ext.login import LoginManager

with

from flask_login import LoginManager
J11
  • 395
  • 3
  • 6
2

This is an environment error -- whatever IDE you're using doesn't have the PYTHONPATH set properly. You can test this out by creating a small test file: test.py, with the following contents:

from os import environ
print environ.get('PYTHONPATH')

If the PYTHONPATH doesn't contain the directory that holds your Flask-Login package, then that's the issue.

mculhane
  • 813
  • 7
  • 7
rdegges
  • 27,994
  • 16
  • 73
  • 100
1

See For me the simple solution is to just remove .ext from flask.ext.login and instead just type flask_login. This works for python 3 and make sure that you have correctly installed your desired package.

Kratik
  • 11
  • 1
0

Strange But it worked when I tried to run the script from Command prompt

C:\Users\dib\Desktop>python foo.py
 * Running on http://127.0.0.1:5000/
127.0.0.1 - - [11/Feb/2014 18:03:52] "GET / HTTP/1.1" 200 -

But when I am trying to run from the python default IDE pressing f5 it is not working.

curiousguy
  • 2,694
  • 6
  • 31
  • 55
0

Initially I installed flask_login on virtual environment. I found out that its trying to find on the machine. So I installed it globally as;

mycomp# pip install -U flask_login

That solved the problem.

7guyo
  • 1,358
  • 13
  • 23
0

The solution is simple. Different versions of the flask run with different codes so just change the code : flask.ext.login to the code: flask_login

It should run smoothly.

Note that this also applies to bootstrap. Actually inorder to find the solution I had the error while importing bootstrap.