0

In my system, I installed the flask_mysqldb, however when I run the app.py file it shows an error like nomodule named flask_mysqldb.

I tried another way of downloading mysqlclient and installed it, but the same error occurs.

Error

The error is  line 2, in <module>
    from flask_mysqldb import MySQL
ModuleNotFoundError: No module named 'flask_mysqldb'

I would appreciate a solution, thanks.

dspencer
  • 4,297
  • 4
  • 22
  • 43
KSM
  • 1
  • You should add More information. 1. Ide you are using . 2. Does this happen only with flask_mysqldb , is there Flask or other packages installed and don't work? .3 how did you install flask_mysqldb ? with pip? – Federico Baù Dec 31 '20 at 16:23
  • Also which Operating system are you using? – Federico Baù Dec 31 '20 at 16:24
  • 1.no ide in cmd I run it 2.no flask is working 3.with pip I installed flask_mysqldb – KSM Jan 02 '21 at 02:22

1 Answers1

0

After some research I can suggest you to do the following:

from flask import Flask, render_template, json, request
from flaskext.mysql import MySQL

mysql = MySQL()
mysql.init_app(app)

Another way to connect and define your credentials to MYSQL would be:

from flaskext.mysql import MySQL
mysql = MySQL()
mysql.init_app(app)

Finally:

from flask import Flask, render_template
from flaskext.mysql import MySQL

mysql = MySQL()
app = Flask(__name__)
mysql.init_app(app)

@app.route('/')
def index():

    return render_template('index.html')


if __name__ == '__main__':
    app.run(debug=True)

Documentation

Mysql Flask Documentacion Oficial

Federico Baù
  • 6,013
  • 5
  • 30
  • 38
  • line 3, in from flaskext.mysql import MySQL ModuleNotFoundError: No module named 'flaskext' Getting this error when I used above solution – KSM Jan 03 '21 at 17:57
  • @KSM I made the code more simple, it works for me Are you sure you run `pip install flask-mysql` ? – Federico Baù Jan 03 '21 at 18:46
  • The same code which I used is now running in pycharm. In cmd prompt only there is a problem.Thank you – KSM Jan 05 '21 at 13:41