Why isn't 'flask' found when running python3 in a terminal?

Viewed 33

In my VSCode terminal, I try to do

python3 
from app import db

and I get

ModuleNotFoundError: No module named 'flask'

In my app.py I have

from flask import Flask, url_for, render_template
from datetime import datetime
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URL"] = "sqlite:///test.db" 
db = SQLAlchemy(app) # Initializes the database 

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

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

class Todo(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    content = db.Column(db.String(200), nullable=False)
    completed = db.Column(db.integer, default=0)
    date_created = db.Column(db.DateTime, default=datetime.utcnow)

    def __repr__(self): # Returns a string when a new element is created
        return '<Tsk %r>' % self.id

I am using virtualenv, and I made sure it was activated both when I installed flask & when I tried to do this.

I am following this tutorial: this tutorial, and at 20:01 he instructs us to do this. What is wrong here?

1 Answers

ModuleNotFoundError is thrown when a package/library is not found. Ensure that you have installed Flask in your virtual environment by running:

pip install flask

or conda install flask if you're using conda.

To check if the package is already installed, run:

pip list
Related