Heroku部署Django应用遇gunicorn: command not found问题求助
Hey there, let's break down why you're hitting this error even though gunicorn is in your requirements.txt!
The Root Cause
Looking at your logs:
2020-02-21T16:22:20.679520+00:00 app[web.1]: bash: gunicorn: command not found
You mentioned you have Pipfile and Pipfile.lock files in your project. Heroku automatically prioritizes Pipenv over pip when it detects these files—meaning it won't use your requirements.txt at all for dependency installation. So even if gunicorn is listed there, it wasn't installed because Heroku used Pipenv instead, and gunicorn is missing from your Pipfile.
Solutions to Try
Option 1: Add gunicorn to your Pipfile
Make sure gunicorn is included in your Pipfile so Heroku installs it via Pipenv:
- Run this command locally to update your Pipfile and Pipfile.lock:
pipenv install gunicorn==20.0.4 - Or manually edit your Pipfile, adding this line under the
[packages]section:gunicorn = "==20.0.4"
Then commit the updated Pipfile and Pipfile.lock, and redeploy to Heroku.
Option 2: Switch back to using requirements.txt
If you prefer to stick with requirements.txt instead of Pipenv, simply delete the Pipfile and Pipfile.lock files from your project. Commit this change and redeploy—Heroku will now use pip to install dependencies directly from your requirements.txt, which already includes gunicorn.
Quick Double-Check
Also, take a quick look at your Procfile command:
gunicorn brendan_project.wsgi -- log file-
There's an extra space between -- and log—it should probably be --log-file (or whatever your intended flag is). This might not be causing the current error, but fixing it will prevent issues once gunicorn is installed.
内容的提问来源于stack exchange,提问作者Brendan Gaturu

