0

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.

blountdj
  • 599
  • 1
  • 11
  • 23
  • are you in a module? do you have an `__init__.py`? PYTHONPATH set? – mattjvincent Feb 22 '18 at 18:29
  • @mattjvincent yes there is a `__init__.py` that is where create_app and db are found. In the command line I've running the file from the app's directory where the manage.py is. – blountdj Feb 22 '18 at 18:54
  • how is called the folder containing the `__init__.py` file and others ? you should use this name for the import statement, maybe you could add the structure of the project to make it clear – PRMoureu Feb 22 '18 at 19:06
  • @PRMoureu thanks for the comment. I realised that my manage.py file was located in the wrong place. It wasn't in the root folder, but a subfolder of the root. Now I've moved it it works using both methods. – blountdj Feb 22 '18 at 19:20

0 Answers0