Flask app deployment fails main:app

Hello Render experts!

I have been trying for over a week to get my simple python flask app hosted. While the build succeeds, the deployment fails.

I have the Start Command set as follows: gunicorn -w 4 main:app

However, I get the following error traceback:

Jun 23 12:34:57 PM  ==> Starting service with 'gunicorn -w 4 main:app'
Jun 23 12:34:59 PM  Traceback (most recent call last):
Jun 23 12:34:59 PM    File "/opt/render/project/src/.venv/bin/gunicorn", line 8, in <module>
Jun 23 12:34:59 PM      sys.exit(run())
Jun 23 12:34:59 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 67, in run
Jun 23 12:34:59 PM      WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
Jun 23 12:34:59 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/gunicorn/app/base.py", line 231, in run
Jun 23 12:34:59 PM      super().run()
Jun 23 12:34:59 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/gunicorn/app/base.py", line 72, in run
Jun 23 12:34:59 PM      Arbiter(self).run()
Jun 23 12:34:59 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/gunicorn/arbiter.py", line 58, in __init__
Jun 23 12:34:59 PM      self.setup(app)
Jun 23 12:34:59 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/gunicorn/arbiter.py", line 118, in setup
Jun 23 12:34:59 PM      self.app.wsgi()
Jun 23 12:34:59 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/gunicorn/app/base.py", line 67, in wsgi
Jun 23 12:34:59 PM      self.callable = self.load()
Jun 23 12:34:59 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
Jun 23 12:34:59 PM      return self.load_wsgiapp()
Jun 23 12:34:59 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
Jun 23 12:34:59 PM      return util.import_app(self.app_uri)
Jun 23 12:34:59 PM    File "/opt/render/project/src/.venv/lib/python3.10/site-packages/gunicorn/util.py", line 359, in import_app
Jun 23 12:34:59 PM      mod = importlib.import_module(module)
Jun 23 12:34:59 PM    File "/opt/render/project/python/Python-3.10.9/lib/python3.10/importlib/__init__.py", line 126, in import_module
Jun 23 12:34:59 PM      return _bootstrap._gcd_import(name[level:], package, level)
Jun 23 12:34:59 PM    File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
Jun 23 12:34:59 PM    File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
Jun 23 12:34:59 PM    File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
Jun 23 12:34:59 PM  ModuleNotFoundError: No module named 'main'

Here is my project structure from GitHub:

teststand-database-utility
├── pyproject.toml
├── poetry.lock
├── README.md
├── src
│   └── ts_data_extractor
│       └── __init__.py
│       └── main.py
│       └── ts_db.py
│       └── database
│            └── __init__.py
│            └── database.py
│       └── file_io
│            └── __init__.py
│            └── file_io.py
└── tests
    └── __init__.py

Any help or advice would be greatly appreciated!

May peace be with you,
Ash

Hi there,

As you main.py is in src/ts_data_extractor I think this would need to run with gunicorn -w 4 src.ts_data_extractor.main:app or cd src/ts_data_extractor; gunicorn -w 4 main:app

Regards,

Keith
Render Support, UTC+10 :australia:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.