17
votes

I have a hard time finding documentation for creating Procfiles using flask with gunicorn and Heroku. Somewhere I found that the syntax is: web: gunicorn my_folder.my_module:app. But I can't make it work. It only works for me when my python script: hello.py is in the root folder of the app. When I put it in a subfolder called app and create a Procfile: web: gunicorn app.hello:app it doesn't work. Only when I use web: gunicorn hello:app and my python script is in the root folder. Can someone explain me the proper syntax of Procfiles for gunicorn on Heroku, and how to make it work when the python script is in a subfolder?

1
Have you added the __init__.py file to the the app folder to make it a Python module?Jean Jung
No haven't added that..CasperTN
And it works when you add that file?Jean Jung
And is that an empty folder or should it contain some code?CasperTN
Just an empty file is Ok, but I am guessing here, I don't know Heroku nor how Procfile works, I just know that python requires __init__.py to see a folder as a Python package.Jean Jung

1 Answers

30
votes

Gunicorn takes a flag, --chdir, that lets you select which directory your Python app lives in. So, if you have a directory structure like:

my-project/
  Procfile
  my_folder/
    my_module.py

and my_module.py contains:

app = Flask(__name__, ...)

You can put the following in your Procfile:

web: gunicorn --chdir my_folder my_module:app