Python 导入错误:没有名为 flask.ext.mysql 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33241924/
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.mysql
提问by Bouchaib Mounir
Hi I am trying to run a python file that has :
嗨,我正在尝试运行一个具有以下内容的 python 文件:
from flask import Flask, render_template, json, request
from flask.ext.mysql import MySQL
from werkzeug import generate_password_hash, check_password_hash
I started in windows, I got the same error :
我从 Windows 开始,我遇到了同样的错误:
ImportError: No module named flask.ext.mysql
Someone told me don't develop python in windows, it's lot of headache, so I started the same project in Ubuntu, but I got the same problem :
有人告诉我不要在windows中开发python,很头疼,所以我在Ubuntu中启动了同一个项目,但我遇到了同样的问题:
vagrant@precise32:/vagrant/FlaskMysql/FlaskApp$ python app.py
Traceback (most recent call last):
File "app.py", line 2, in <module>
from flask.ext.mysql import MySQL
File "/usr/local/lib/python2.7/dist-packages/flask/exthook.py", line 87, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named flask.ext.mysql
Please your help is appreciated.
感谢您的帮助。
采纳答案by youngeun
It seems like a virtualenv config problem you should get rid of old virtualenv and make a new one like this
这似乎是一个 virtualenv 配置问题,你应该摆脱旧的 virtualenv 并像这样创建一个新的
virtualenv yournewvirtualenv --python=/usr/bin/python3.4
This is the link I referenced: https://www.pythonanywhere.com/forums/topic/2877/
回答by Celeo
回答by Extrct
Here is the official Flask-MySQL documentation: https://flask-mysql.readthedocs.org/en/latest/#You'll find that the current import syntax is as follows:
这里是 Flask-MySQL 的官方文档:https: //flask-mysql.readthedocs.org/en/latest/#你会发现当前的导入语法如下:
from flaskext.mysql import MySQL
回答by Natalia2q
I had the same problem, so I installed flask-mysql
using:
我遇到了同样的问题,所以我flask-mysql
使用以下方法安装:
$ pip install flask-mysql
and the module name is flaskext.mysql
模块名称是 flaskext.mysql
回答by Mona Jalal
On Windows:
在 Windows 上:
pip install Flask-MySQL
On Mac:
在 Mac 上:
pip install flask-mysql
回答by Alireza
It's flaskext, so...
这是flaskext,所以...
Change
改变
from flask.ext.mysql import MySQL
to
到
from flaskext.mysql import MySQL
回答by Mobin Yasin
First from flaskext.mysql import MySQL
worked then pip install Flask-MySQL
also worked finally... it was driving me nuts! I had taken to many routes to fix it.
首先from flaskext.mysql import MySQL
工作然后pip install Flask-MySQL
最后也工作......这让我发疯!我已经采取了很多途径来修复它。
回答by Pooja Khatri
I was facing the same error. First I installed flask-MySQL
我面临同样的错误。首先我安装了flask-MySQL
pip install flask-mysql
Then added below-line in app.py file
然后在 app.py 文件中添加下面的行
from flaskext.mysql import MySQL
It worked.
有效。