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

笑着哭i 提交于 2019-11-27 10:56:06

Try:

web: gunicorn --pythonpath app app.wsgi

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

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

I like eikonomega's answer, but I wanted to add how I solved a similar problem:

Mine was a bit harder,as my file was in more folders

Instead of adding the a 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 script1.py, inside an answers folder, which is inside the app8-web-financial-graph folder.

web: gunicorn app8-web-financial-graph.answers.script1:app
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!