'from main import db' gives ModuleNotFoundError: No module named 'main'


I created an SQLite3 database, called page.db.

I am trying to use it in python.

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import sqlite3

class tabb(db.Model):

After writing this code, I enter python shell and run the command from main import db. It shows an error saying:

ModuleNotFoundError: No module named 'main'

How can I fix this?


Are you sure the filname is main and that you are in the same directory as main.py when opening the python interpreter?

Answered By – Arjun

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published