简体   繁体   English

ModuleNotFoundError:没有名为“flask-mysqldb”的模块

[英]ModuleNotFoundError: No module named 'flask-mysqldb'

I am using Windows10 Home,I have Python3.9.1 and Visual Studio Code.These are mu code:我正在使用 Windows10 Home,我有 Python3.9.1 和 Visual Studio Code。这些是 mu 代码:

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.我有 about.html 和 index.html 文件。我知道它们是正确的,因为我使用的是另一个应用程序。

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运行此代码时出现此错误。我对软件非常陌生。所以我不知道该怎么办

You need to install all the modules that are used within your project which in your case is flask_mysqldb.您需要安装项目中使用的所有模块,在您的情况下是flask_mysqldb。 Install it with the following cmd:使用以下 cmd 安装它:

pip install flask-mysqldb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM