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.

3
  • 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? Commented Dec 31, 2020 at 16:23
  • Also which Operating system are you using? Commented Dec 31, 2020 at 16:24
  • 1.no ide in cmd I run it 2.no flask is working 3.with pip I installed flask_mysqldb Commented Jan 2, 2021 at 2:22

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

line 3, in <module> from flaskext.mysql import MySQL ModuleNotFoundError: No module named 'flaskext' Getting this error when I used above solution
@KSM I made the code more simple, it works for me Are you sure you run pip install flask-mysql ?
The same code which I used is now running in pycharm. In cmd prompt only there is a problem.Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.