Muhammad Irfan Shahzad
Muhammad Irfan Shahzad

Reputation: 115

Import Error in flask importing MYSQL in python in vs code?

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)

This is the library code in vs code that do not show error here

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

Upvotes: 0

Views: 881

Answers (2)

Muhammad Irfan Shahzad
Muhammad Irfan Shahzad

Reputation: 115

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

Upvotes: 1

Ashish Papanai
Ashish Papanai

Reputation: 88

**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

Upvotes: 0

Related Questions