Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku can't find gunicorn command

I'm trying to put a small Flask app on Heroku. When it starts, it gives me the following message, from the logs:

2015-03-11T01:05:26.737788+00:00 heroku[web.1]: State changed from crashed to starting
2015-03-11T01:05:31.409851+00:00 heroku[web.1]: Starting process with command `gunicorn app:app`
2015-03-11T01:05:33.863601+00:00 app[web.1]: bash: gunicorn: command not found
2015-03-11T01:05:34.644419+00:00 heroku[web.1]: Process exited with status 127
2015-03-11T01:05:34.668264+00:00 heroku[web.1]: State changed from starting to crashed

My Procfile is

web: gunicorn application:app

, and application.py is the file I want to run. I looked up this problem and saw that it was sometimes caused by gunicorn not being in requirements.txt, but my requirements.txt has it, with this line:

gunicorn==19.3.0

. I tried running

heroku run pip install gunicorn

and it told me it installed gunicorn-19.3.0 successfully. But when I tried running it on Heroku with

heroku run gunicorn

it against gave me the "bash: gunicorn: command not found" message.

like image 794
blacktrance Avatar asked Mar 11 '15 01:03

blacktrance


People also ask

What is Gunicorn in Heroku?

Gunicorn is a pure-Python HTTP server for WSGI applications. It allows you to run any Python application concurrently by running multiple Python processes within a single dyno. It provides a perfect balance of performance, flexibility, and configuration simplicity.

Does heroku use Gunicorn?

Gunicorn is a python WSGI HTTP server that will serve your Flask application at heroku.

How do I deploy flask app to Heroku?

Deploying Flask App on Heroku Follow the following steps to create the sample application for this tutorial. STEP 1 : Create a virtual environment with pipenv and install Flask and Gunicorn . STEP 2 : Create a “Procfile” and write the following code. STEP 3 : Create “runtime.


2 Answers

Add gunicorn to requirements.txt.

In pursuit of 12-factor apps, changes to the filesystem made with heroku run are ephemeral.

like image 85
brennan Avatar answered Sep 30 '22 02:09

brennan


I ran into this same issue.
After doing some research, I found this tutorial where they explain that any "local" changes (like importing/using a new module) must be "installed" in the heroku app using pipenv. So in this case what I did was:

$ pipenv install gunicorn

This will "install" gunicorn in you app and add an entry into your (or create a new) Pipfile, which is how Heroku keeps track of the dependencies it needs to install for your app (I believe the use of requirements.txt is still supported, but not what they recommend).

Then, in order to 'activate' the pip environment that has gunicorn installed you must run:

$ pipenv shell

NOTE: You can test whether it worked or not by running $ heroku local

$ heroku local
[WARN] No ENV file found
23:10:25 web.1   |  /bin/sh: gunicorn: command not found
23:10:25 web.1   Exited with exit code 127

With pip environment activated:

$ pipenv shell
Spawning environment shell (/bin/bash). Use 'exit' to leave.
. /Users/carlos/.local/share/virtualenvs/app-jKOcg6b1/bin/activate
bash-3.2$ . /Users/carlos/.local/share/virtualenvs/app-jKOcg6b1/bin/activate
(app-jKOcg6b1) bash-3.2$ heroku local
[WARN] No ENV file found
06:31:12 web.1   |  [2018-06-05 06:31:12 -0600] [28531] [INFO] Starting gunicorn 19.8.1
06:31:13 web.1   |  [2018-06-05 06:31:12 -0600] [28531] [INFO] Listening at: http://0.0.0.0:5000 (28531)
06:31:13 web.1   |  [2018-06-05 06:31:12 -0600] [28531] [INFO] Using worker: sync
06:31:13 web.1   |  [2018-06-05 06:31:12 -0600] [28535] [INFO] Booting worker with pid: 28535
like image 42
beasclo Avatar answered Sep 30 '22 04:09

beasclo