Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask - ImportError: No module named app

First I created __init__.py

from flask import Flask  app = Flask(__name__) 

Then in a separate file, in the same directory, run.py

from app import app   app.run(     debug = True ) 

When I try to run run.py, I get the error

Traceback (most recent call last):   File "run.py", line 1, in <module>     from app import app  ImportError: No module named app 
like image 520
onepiece Avatar asked Mar 28 '14 11:03

onepiece


People also ask

Why is there no module named flask?

The Python "ModuleNotFoundError: No module named 'flask'" occurs when we forget to install the Flask module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install Flask command.


1 Answers

__init__.py is imported using a directory. if you want to import it as app you should put __init__.py file in directory named app

a better option is just to rename __init__.py to app.py

like image 104
Elisha Avatar answered Oct 07 '22 18:10

Elisha