[Django]-How can I modify Procfile to run Gunicorn process in a non-standard folder on Heroku?

79👍

Try:

web: gunicorn --pythonpath app app.wsgi

71👍

As @Graham Dumpleton stated in his answer, the OP’s problem could be solved by modifying his Procfile to the following:

web: gunicorn --pythonpath app app.wsgi

Why this works:

  • Remember, that the Procfile is simply used by Heroku to start processes. In this case, gunicorn processes.
  • Gunicorn’s --pythonpath argument allows you to dynamically attach a directory to the list of directories that the Python runtime searches for when do module look-ups.
  • By adding --pythonpath app to the gunicorn command, the interpreter was basically told ‘look inside of the app directory for a package (also) called app which contains a module called wsgi.`

The generic names of the folders in the OP’s question can obscure the syntax of the command, which is as follows:
gunicorn --pythonpath <directory_containing_package> <package>.<module>

More Info:
Gunicorn Documentation

6👍

I made a ugly hack for getting this working. So I’m going to post my answer, but I hope you guys can come up with a better solution

Procfile

web: sh ./app/run.sh

app_project/app/run.sh

#!/bin/bash

cd app
gunicorn app.wsgi
👤Derek

5👍

If your file is nested in folders, the following will make more sense.

Instead of adding the path to the PYTHONPATH environmental variable, instead I referenced it like you would reference modules in a package:

In my case, the app object was in a scriptC.py, inside folderB, which is inside the folderA.

web: gunicorn folderA.folderB.scriptC:app

Leave a comment