ImportError: No module named flask.ext.login

匿名 (未验证) 提交于 2019-12-03 02:56:01

问题:

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.

回答1:

Install pip and then use the following command:

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



回答2:

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 


回答3:

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.



回答4:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!