Skip to content
Advertisement

ModuleNotFoundError: No module named ‘flask-mysqldb’

I am using Windows10 Home,I have Python3.9.1 and Visual Studio Code.These are mu code:

from flask import Flask,render_template,flash,redirect,url_for,session,logging,request
from flask_mysqldb import MySQL
from wtforms import Form,StringField,TextAreaField,PasswordField,validators
from passlib.hash import sha256_crypt

class RegisterForm(Form):
    name = StringField("Name  Surname",validators=[validators.Length(min=4,max=25)])
    username = StringField("User name",validators=[validators.Length(min=5,max=35)])
    email = StringField("Email Adress",validators=[validators.Email(message = "Please enter a valid email.")])
    password = PasswordField("Password:",validators=[
        validators.DataRequired(message = "Please enter a password"),
        validators.EqualTo(fieldname="confirm",message = "Your password is not correct.")
    ])
    confirm = PasswordField("Verify password")
app = Flask(__name__)

app.config["MYSQL_HOST"] = "localhost"
app.config["MYSQL_USER"] = "root"
app.config["MYSQL_PASSWORD"] =""
app.config["MYSQL_DB"] ="blog"
app.config["MYSQL_CURSORCLASS"] = "DictCursor"

mysql = MySQL(app)

@app.route("/")
def index():
    return render_template("index.html")

@app.route("/about")
def about():
    return render_template("about.html")

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



and I have about.html and index.html file.I know they are correct because I was use they another app.

When I run this code I take this error.I am very new about the software.So I don’t know what should I do

Advertisement

Answer

You need to install all the modules that are used within your project which in your case is flask_mysqldb. Install it with the following cmd:

pip install flask-mysqldb
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement