Search code examples
pythonvisual-studio-codeflask-mysql

How can I solve ModuleNotFoundError: No module named 'flask_mysqldb' Error in Vs.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

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

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

I use Python 3.7.3 version. I installed flask-mysqldb.This code doesn't work and program give ModuleNotFoundError: No module named 'flask_mysqldb' Error in Vs.Code but this code work in Pycharm. Pycharm's Pyton interpreter is the same with Vs.Code's. How can I solve this problem ?


Solution

  • You need to config the env path to the VS Code.

    List of environments VS Code found. You can choose the environment in the button bar of VS Code

    Usually, VS Code can get env from /usr/bin/ directory and from env/ directory inside your working folder. You can create a python environment by using python3 -m venv env command

    Select environment by clicking this inside the bottom bar( this is only appear when you open *.py file. Here is available environment which VS Code get from your PC