0

I want to connect Mysql to Flask.

Before adding this configuration part:

app = Flask(__name__)
mysql = MySQL()
app.config['MYSQL_DATABASE_USER'] = 'username'
app.config['MYSQL_DATABASE_PASSWORD'] = 'password'
app.config['MYSQL_DATABASE_DB'] = 'dbname'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
mysql.init_app(app)

I tried to import from flaskext.mysql import MySQL but after that, I face with this error:

from flaskext.mysql import MySQL

ImportError: No module named 'flaskext'

Then I tried pip install flaskext.mysql but got this error:

Could not find a version that satisfies the requirement flaskext.mysql (from versions: ) No matching distribution found for flaskext.mysql

So what should I do then?

Community
  • 1
  • 1
niloofar
  • 2,244
  • 5
  • 23
  • 44
  • 1
    `pip install flask-mysql` after `from flaskext.mysql import MySQL` – dsgdfg Jul 21 '16 at 10:35
  • I did but got this error `ImportError: No module named 'ConfigParser'` – niloofar Jul 21 '16 at 10:47
  • Check this : http://stackoverflow.com/questions/31662194/python-2-7-no-module-named-configparser – dsgdfg Jul 21 '16 at 10:55
  • Maybe that error backs to being not python 3 compatible, as what I understand from this link `https://github.com/theatlantic/django-mysqlndb-backend/issues/3` – niloofar Jul 21 '16 at 11:18
  • `MySQL-python dependency is not python 3 compatible` yes you are right ! This link explain using `django-mysqlndb-backend` module(for bugs ). – dsgdfg Jul 21 '16 at 12:21

2 Answers2

0

The '.' is missing, try from flask.ext.mysql import MySQL. But if you are using Flask 0.11, extension imports of the form flask.ext.foo have been deprecated you should use from flask_foo. Also see this.

simanacci
  • 2,197
  • 3
  • 26
  • 35
0

You only need to specify the version of flask-mysql you intend to install. This works for me.

pip install Flask-MySQL==1.5.2

AdekunleCodez
  • 120
  • 1
  • 1
  • 8