Heroku找不到gunicorn命令。

11

我正在尝试将一个小的Flask应用程序放到Heroku上。当它启动时,从日志中给了我以下信息:

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

我的 Procfile 是

web: gunicorn application:app

我的目标是运行application.py这个文件。我查了一下这个问题,发现有时是由于requirements.txt中没有gunicorn导致的,但我的requirements.txt里有它,它被列在这一行中:

and application.py 是我要运行的文件。我查了一下这个问题,发现有时是由于 requirements.txt 中没有 gunicorn 导致的,但我的 requirements.txt 里有它,包含以下这行:

gunicorn==19.3.0
我尝试运行。
heroku run pip install gunicorn

它告诉我已经成功安装了 gunicorn-19.3.0。但是当我在 Heroku 上尝试运行它时,出现了问题。

heroku run gunicorn

运行它后出现了"bash: gunicorn: command not found"的错误信息。

5个回答

4

我遇到了同样的问题。
经过一番调查,我找到了这个教程,其中他们解释说任何“本地”更改(如导入/使用新模块)必须使用pipenv在heroku应用程序中进行“安装”。所以在这种情况下,我所做的是:

$ pipenv install gunicorn

这将在您的应用中“安装”gunicorn,并添加一个条目到您的(或创建新的)Pipfile中,这是Heroku跟踪安装应用所需依赖关系的方式(我相信仍支持使用requirements.txt,但不是他们推荐的方法)。
然后,为了“激活”具有安装gunicorn的pip环境,您必须运行:
$ pipenv shell

注意:您可以通过运行$ 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

使用pip环境:

$ 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

这对我起作用了。我必须使用pipenv install在requirements.txt中重新安装一切。 - qzx

3

gunicorn添加到requirements.txt中。

为了追求12因素的应用程序,在使用heroku run进行文件系统更改时,这些更改是短暂的


2

只需将以下这行代码添加到你的requirements.txt文件中即可:

gunicorn==19.7.1

这就是我修复它的方法。

0

我在运行Ubuntu 18.04.2 LTS bionic时遇到了这个问题。解决方法是更新PATH变量!

在~/.profile文件中,我添加了以下几行:

if [ -d "$HOME/.local" ] ; then
    PATH="$HOME/.local:$PATH"
fi
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

我已将 "runtime.txt" 更改为与我的 Python 3 版本相匹配。我不确定是否有必要,但现在它是 python-3.6.7

另外,由于我安装了各种版本的 python 和 pip,我的本地安装和运行命令如下:

python3 -m venv getting-started
pip3 install -r requirements.txt
python3 manage.py migrate #I had already created the database
python3 manage.py collectstatic
heroku local

0

以下是一个清单:

  1. 在本地环境中安装Gunicorn并使用pip freeze > requirements.txt将其添加到requirements.txt中。将更改提交到Heroku。

  2. 从Heroku和本地环境中删除PipfilePipfile.lock,只保留requirements.txt


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接