Flask Error Launching app using manager.run()

629 Views Asked by At

I have an app which runs fine inside pycharm when I run the manage file consisting of:

#!/usr/bin/env python
from app import create_app, db
from app.models import User, Role
from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand

app = create_app('default')
manager = Manager(app)
migrate = Migrate(app, db)

def make_shell_context():
    return dict(app=app, db=db, User=User, Role=Role)

manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)


if __name__ == '__main__':
    app.run()

However, if I replace app.run() with manager.run() and then run the file from the command line I receive the following error in respect of line 2 from app import create_app, db:

ModuleNotFoundError: No module named 'app'

Any ideas why this is or how to resolve it? Not sure it can be found one way but not the other.

Many thanks

*EDIT I should add that app is not a file called app.py. It is a variable created in the __init__.py file. This is how it is done in an example I'm following and that doesn't encounter the error.

0

There are 0 best solutions below