Having Trouble Using Flask CLI, Module Not Found

I have an application withe following structure:

src
|-__init__.py
|-run_flask_app.py
|-flask_app
  |-__init__.py
  |-app.py (file name is app.py in the flask_app package, just to be clear)
  |-config.py

In the app.py I have an applicaiton factory:


def create_app(environment_import_path):
    print('environment_import_path', environment_import_path)
    print('basedir',  os.path.abspath(os.path.join('../', os.path.dirname(__file__))))
    print('basedir2',  os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

    app = Flask(__name__, instance_relative_config = True,
                instance_path=os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

    print('app.instance_path', app.instance_path)

    app.config.from_object(environment_import_path)

    db.init_app(app)
    migrate.init_app(app, db)

    register_blueprints(app)

    return app

While in the src directory I run

flask --app 'flask_app.app:create_app("flask_app.config.DevelopmentConfig")' run

and get an error:

environment_import_path flask_app.config.DevelopmentConfig
basedir /Users/victorreichert/Documents/Python/CFNFT_PROJ/src/flask_app
basedir2 /Users/victorreichert/Documents/Python/CFNFT_PROJ/src
app.instance_path /Users/victorreichert/Documents/Python/CFNFT_PROJ/src
Traceback (most recent call last):
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/venv/bin/flask", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/venv/lib/python3.12/site-packages/flask/cli.py", line 1105, in main
    cli.main()
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/venv/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/venv/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/venv/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/venv/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/venv/lib/python3.12/site-packages/click/decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/venv/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/venv/lib/python3.12/site-packages/flask/cli.py", line 953, in run_command
    raise e from None
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/venv/lib/python3.12/site-packages/flask/cli.py", line 937, in run_command
    app: WSGIApplication = info.load_app()
                           ^^^^^^^^^^^^^^^
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/venv/lib/python3.12/site-packages/flask/cli.py", line 335, in load_app
    app = locate_app(import_name, name)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/venv/lib/python3.12/site-packages/flask/cli.py", line 264, in locate_app
    return find_app_by_string(module, app_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/venv/lib/python3.12/site-packages/flask/cli.py", line 178, in find_app_by_string
    app = attr(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/flask_app/app.py", line 42, in create_app
    app.config.from_object(environment_import_path)
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/venv/lib/python3.12/site-packages/flask/config.py", line 254, in from_object
    obj = import_string(obj)
          ^^^^^^^^^^^^^^^^^^
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/venv/lib/python3.12/site-packages/werkzeug/utils.py", line 612, in import_string
    raise ImportStringError(import_name, e).with_traceback(
  File "/Users/victorreichert/Documents/Python/CFNFT_PROJ/src/venv/lib/python3.12/site-packages/werkzeug/utils.py", line 604, in import_string
    module = __import__(module_name, globals(), locals(), [obj_name])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
werkzeug.utils.ImportStringError: import_string() failed for 'flask_app.config.DevelopmentConfig'. Possible reasons are:

- missing __init__.py in a package;
- package or module path not included in sys.path;
- duplicated package or module name taking precedence in sys.path;
- missing module, class, function or variable;

Debugged import:

- 'flask_app' not found.

Original exception:

ModuleNotFoundError: No module named 'flask_app'

I have set instance_relative_config and the instance_path to the be the src package/directory. Why can’t flask find the the ‘flask_app.config.DevelopmentConfig’ in the app.config.from_object(environment_import_path) line?

I’m running python 3.12 and Flask 3.0.3. I’m really stuck. When I run the app with run_flask_app.py it works fine.

run_flask_app.py

from flask_app.app import create_app

environment_import_path = 'flask_app.config.DevelopmentConfig'

app = create_app(environment_import_path)

if __name__ == '__main__':

    app.run(host="localhost", port=8000)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật