'Error: module 'src' has no attribute 'app.py'

I am trying to import my app from app.py file into my manage.py file. When I run the command python manage.py create_db I get the error:

Usage: manage.py create_db [OPTIONS] Try 'manage.py create_db --help' for help.

Error: module 'src' has no attribute 'app.py'

I have tried:

import src.app

from .src import app

from src import app

from src.app import app

my file structure is

backend/
   src/
     __init__.py
     app.py
     config.py
   manage.py
   entrypoint.sh

Here is my manage.py file:

from flask.cli import FlaskGroup

import src.app
from src.models import User, Session, engine, Base

cli = FlaskGroup(src.app.app)

# if needed, generate database schema
session = Session()

@cli.command("create_db")
def create_db():
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

@cli.command("seed_db")
def seed_db():
    session.add(User(email="[email protected]",first_name="Adrian",last_name="Searles",username="asearle",password="Pspgame12"))
    session.commit()


if __name__ == "__main__":
    cli()


Solution 1:[1]

Try adding empty __init__.py in src directory. It makes python treat it as a module:

https://stackoverflow.com/a/448279/11298974

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 yjay