Error when launching a Flask application

Hi
I have a Flask application which does not seem to get executed after its deployment.
This application was successfully running on Heroku deployment.

I tried to run the same command as the one used for Heroku deplyoment as described here but I am getting the following error:

The scr folder is where the app.py file is

Can you help please?

Many thanks
Marco

Hey Marco. Do you mind posting your Start Command? I noticed there’s a double quote to the left of the word “app” in the following line: ModuleNotFoundError: No module named '"app', I wonder if the error is related to that.

Hi Bryan
this is the command:
gunicorn “src.app:create_main_and_celery_apps(config_type=‘production’)” and correct error is this one:

I also tried changing the command like this

  • gunicorn ‘src.app:create_main_and_celery_apps()’
  • gunicorn “src.app:create_main_and_celery_apps()”

and I get a the same error as before

I hope it helps
Many thanks

Hi Marco. This may not be an issue with Render, but maybe with your folder structure and app.py module. Additionally, I just learned that in the gunicorn app:app command, the first “app” is the name of your Python module (e.g., app.py), and the second “app” is the variable name of the Flask instance inside app.py (e.g., app = Flask(__name__)).

With that being said, assuming that your Flask instance is called create_main_and_celery_apps and the app.py module is in the project’s src folder, try any of the following:

  • gunicorn src.app:create_main_and_celery_apps
  • gunicorn --chdir /opt/render/project/src/src app:create_main_and_celery_apps

Lastly, you should be able to test this locally on your machine, which might be faster than waiting to redeploy on Render (see below). I hope this helps. Have fun!

I just learned that a Root Directory optional field exists in the Settings menu of your Render Flask service instance. You could also try filling this field with src and updating your Start Command to the following below (Disclaimer: I have not tested this myself :slight_smile:).

gunicorn app:create_main_and_celery_apps

Hi Bryan
thanks for your help. I figured out that the problem was due the quotes in the command. Once removed the application is launched successfully
Thanks again

1 Like

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