Heroku + gunicorn not working (bash: gunicorn: command not found )
Asked Answered
D

19

87

I successfully install gunicorn:

remote: -----> Removing .DS_Store files
remote: -----> Python app detected
remote: -----> Installing dependencies with pip
remote:        Collecting gunicorn==19.0.0 (from -r requirements.txt (line 1))
remote:          Downloading gunicorn-19.0.0.tar.gz (382kB)
remote:        Installing collected packages: gunicorn
remote:          Running setup.py install for gunicorn
remote:        Successfully installed gunicorn-19.0.0

My Procfile:

web: gunicorn myapp:app --log-file=-

But the app crashes when deployed:

bash: gunicorn: command not found 

I tried adding the heroku python buildpack, but no luck. If I roll back to a previous commit (where requirements.txt and Procile are both unchanged), it works:

heroku/web.1:  Starting process with command `gunicorn myapp:app --log-file=-` 
app/web.1:  2015-10-08 17:04:18 [3] [INFO] Listening at: http://0.0.0.0:51854 (3)
Davidoff answered 8/10, 2015 at 17:2 Comment(0)
D
22

The issue seemed to fix itself after uninstalling all requirements remotely, and reinstalling them.

Davidoff answered 8/10, 2015 at 19:44 Comment(7)
Deploy an empty requirements file, then deploy the original one.Davidoff
An empty requirements file give me: "You must give at least one requirement to install (see "pip help install")"Midiron
Patrice good warning, I ran into this too so I'm going to remove all but the first from my requirements file.Izolaiztaccihuatl
This is such a cryptic solution!Conjurer
@Davidoff You are right about emptying the requirements, it build the app, but nevertheless it crashes again in my case when pushing the full requirmentsParish
uploading empty or fresh copy of requirements.txt worked on my side.Surrebuttal
@Davidoff can you specify the steps in your answer, how to uninstall requirements remotely?Agile
T
144

Make sure gunicorn is in your requirements.txt

Takeshi answered 8/10, 2015 at 17:6 Comment(3)
It is there, notice the remote: Collecting gunicorn==19.0.0 (from -r requirements.txt (line 1)) in my question. Thanks though.Davidoff
Try recreate your App in heroku.Takeshi
I recreated it, same issue.Davidoff
D
22

The issue seemed to fix itself after uninstalling all requirements remotely, and reinstalling them.

Davidoff answered 8/10, 2015 at 19:44 Comment(7)
Deploy an empty requirements file, then deploy the original one.Davidoff
An empty requirements file give me: "You must give at least one requirement to install (see "pip help install")"Midiron
Patrice good warning, I ran into this too so I'm going to remove all but the first from my requirements file.Izolaiztaccihuatl
This is such a cryptic solution!Conjurer
@Davidoff You are right about emptying the requirements, it build the app, but nevertheless it crashes again in my case when pushing the full requirmentsParish
uploading empty or fresh copy of requirements.txt worked on my side.Surrebuttal
@Davidoff can you specify the steps in your answer, how to uninstall requirements remotely?Agile
P
17

I was missing the heroku/python buildpack so I went to the dashboard and:

Settings -> Add buildpack -> heroku/python
Parboil answered 28/5, 2018 at 0:3 Comment(0)
P
17

install gunicorn in your virtual environment

pip install gunicorn

then update your requirements.txt file

pip freeze > requirements.txt
Painful answered 9/6, 2020 at 9:51 Comment(1)
I transitioned to poetry and forgot to install gunicorn because it is only relevant when deploying.Progestational
M
12

If you have both requirements.txt and Pipfile in the project root, then I would recommend to delete the Pipfile and have all your requirements listed in requirements.txt file (including gunicorn).

It will then show: "Installing requirements from pip", and all of your requirements listed in requirements.txt will be installed.

Minicam answered 12/2, 2019 at 19:26 Comment(0)
M
4

Heroku's Python docs seem to be outdated... Apparently they now prefer a Pipfile over requirements.txt, but thankfully you can easily generate one with pipenv.

Try this:

$ pip3 install --user pipenv to install pipenv

$ pipenv install gunicorn to add gunicorn to the pipfile

$ pipenv shell to activate

I had the exact same error, and this worked for me!

Mulderig answered 7/4, 2020 at 5:23 Comment(0)
C
2

After checking that gunicorn is in requirements.txt run:

pip install -r requirements.txt

My output contained several Requirement already satisfied: ... but gunicorn wasn't installed:

Collecting gunicorn (from -r requirements.txt (line 2))
Using cached ...

Installing collected packages: gunicorn
Successfully installed gunicorn-19.9.0
Comstockery answered 15/8, 2019 at 6:32 Comment(0)
T
2

In my case, there was a conflict since I had Pipfile, Pipfile.lock and requirements.txt files all at once in the same directory / project.

Heroku was not installing anything from requirements.txt, hence the same gunicorn error as everyone here.

Thiel answered 12/4, 2020 at 21:51 Comment(0)
F
1

add gunicorn in requirements.txt solved my issue.

Fronia answered 16/8, 2020 at 7:12 Comment(0)
L
1

In my case, even though gunicorn was in requirements.txt, gunicorn was not installing because of the Pipfile present. I removed the Pipfile from my github repository and redeployed with success.

The following short tutorial was also helpful to make sure I had the essentials of runtime.txt, wsgi.py, and Procfile configured correctly.

https://www.geeksforgeeks.org/deploy-python-flask-app-on-heroku/

Lodhia answered 4/12, 2020 at 17:53 Comment(0)
H
1

I was facing the same problem but after adding gunicorn===<latest-version> to requirements.txt file it was fixed.

Honeysweet answered 6/5, 2021 at 2:12 Comment(0)
I
1

install gunicorn in your virtual environment

pip install gunicorn

then update your requirements.txt file

pip freeze > requirements.txt

Add file to github

git add .

Commit

git commit -m "Added gunicorn"

Push back to heroku

git push heroku branch_name:main
Institutionalism answered 27/7, 2022 at 11:14 Comment(0)
P
0

In my case I had an issue inside 'Procfile'.
I removed : after gunicorn.

web: gunicorn: app:app -> web: gunicorn app:app

Palate answered 25/12, 2019 at 6:28 Comment(0)
C
0

You also need to be sure that when running your git push heroku master that the requirements are installed from requirements.txt and not from pipfile or pipfile.lock. So make sure you remove these files from you cd directory if you are installing your dependencies with requirements.txt

Comose answered 5/6, 2020 at 0:8 Comment(0)
C
0

In my case it was because in Pipfile gunicorn was under the dev-packages. Installing it as regular package worked. Only with Pipfile. No requirements.txt necessary.

Connor answered 12/12, 2020 at 1:7 Comment(0)
C
0

I don't know why it worked, but I was having the same issue, and after reading other suggestions, I ended up deleting my requirements.txt file (even though it had gunicorn) and running pip freeze > requirements.txt again and it fixed the problem.

Cozmo answered 4/6, 2021 at 16:24 Comment(0)
S
0

In my case, my Heroku app was missing a python buildpack and thus not installing any package.

I fixed this by adding one : Settings > Buildpacks > Add buildpack > python

Schacker answered 3/8, 2021 at 9:10 Comment(0)
C
0

I tried this and worked for me

  1. delete gunicorn from requirements.txt

  2. $ pip3 install --user pipenv to install pipenv

  3. $ pipenv install gunicorn to add gunicorn to the pipfile

  4. $ pipenv shell to activate

  5. push

Crewelwork answered 26/9, 2022 at 22:45 Comment(0)
R
-1

it happens when gunicorn is Not installed properly... and for insatlling again, installor can only install a file if there is change in requirments.txt

so follow below steps :-

first, install a Empty or only one thing in requirments.txt will make the installor to install something becoz there is change in requirments.txt and follow full complete setps after like git inti .... so on

after that repeat the all steps with full requirments.txt file it will work surely....

mine solved this way.. thanks

Reba answered 29/9, 2021 at 16:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.