Flask - ImportError: No module named app

onepiece picture onepiece · Mar 28, 2014 · Viewed 89.6k times · Source

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

Answer

Elisha picture Elisha · Mar 28, 2014

__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