Python 导入错误:没有名为 flask.ext.login 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21701174/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ImportError: No module named flask.ext.login
提问by curiousguy
I have a problem with flask_login module.
我有flask_login 模块的问题。
i have installed flask_login module successfully. Also from the command prompt i can run this script easily with no error:
我已经成功安装了 Flask_login 模块。同样从命令提示符,我可以轻松地运行这个脚本,没有错误:
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.
我在做什么错误。我对这个烧瓶很陌生。提前致谢。
回答by curiousguy
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 f5it is not working.
但是当我尝试从 python 默认 IDE 运行时,pressing f5它不起作用。
回答by rdegges
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:
这是环境错误——您使用的任何 IDE 都没有正确设置 PYTHONPATH。您可以通过创建一个小的测试文件来测试它:test.py,其中包含以下内容:
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.
如果 PYTHONPATH 不包含保存 Flask-Login 包的目录,那就是问题所在。
回答by Najeebullah Shah
Install pip and then use the following command:
安装 pip,然后使用以下命令:
C:\Python27\scripts>pip install Flask-Login
C:\Python27\scripts>pip install Flask-Login
回答by prem kumar
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.
要查找flask-login 版本,您可以在终端中运行以下命令。只需更改名称即可了解其他软件包的版本。
pip show flask-login
回答by J11
If you have already installed flask-login by
如果您已经通过以下方式安装了flask-login
$pip install flask_login
Try replacing the
尝试更换
from flask.ext.login import LoginManager
with
和
from flask_login import LoginManager
回答by 7guyo
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;
最初我在虚拟环境中安装了flask_login。我发现它试图在机器上找到。所以我在全球范围内安装了它;
mycomp#pip install -U flask_login
mycomp# pip install -U flask_login
That solved the problem.
那解决了问题。
回答by Kratik
See For me the simple solution is to just remove .ext from flask.ext.loginand instead just type flask_login. This works for python 3 and make sure that you have correctly installed your desired package.
请参阅对我来说,简单的解决方案是从 .ext 中删除 .extflask.ext.login而只是键入flask_login。这适用于 python 3,并确保您已正确安装所需的软件包。
回答by Sparrowan
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
解决方法很简单。不同版本的烧瓶使用不同的代码运行,所以只需将代码:flask.ext.login 更改为代码: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.
请注意,这也适用于引导程序。实际上,为了找到解决方案,我在导入引导程序时遇到了错误。

