Home > database >  Import Error in flask importing MYSQL in python in vs code?
Import Error in flask importing MYSQL in python in vs code?

Time:09-22

from flask import Flask, render_template,redirect, 
session,url_for,request
from flask_mysqldb  import MYSQl
app = Flask(__name__)
app.secret_key="12345678"

app.config["MYSQL_HOST"] = "localhost"
app.config["MYSQL_USER"]="root"
app.config["MYSQL_PASSWORD"]="123457"
app.config["MYSQL_DB"] = "management"
db = MYSQL(app)

In this snap showing import error while library already installed

This is the snap of flask mysqldb installed

I installed mysql. but when i run in python it giving error how do i remove import error for flask_mysqldb.In second snap showing import error while library already installed.In third snap, This is the snap of flask mysqldb is installed

CodePudding user response:

For import MySQL in flask. The Syntax are from flask_mysqldb import MySQL. 'y' always in lowercase in " MySQL"

CodePudding user response:

**Did you install flask-mysql? **

If you haven't, Install it by running the following command in command prompt.

pip install flask-mysql

If you've already installed flask-mysql, as I can see from the screenshots of the error your import statement is incorrect,

Import it as:

from flask_mysql import MySQL

  • Related