Heroku找不到gunicorn命令

2024-04-26 02:34:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在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

我的程序文件是

web: gunicorn application:app

,application.py是我要运行的文件。我查了一下这个问题,发现它有时是由gunicorn不在requirements.txt中引起的,但是我的requirements.txt中有它,这行:

gunicorn==19.3.0

是的。 我试过跑步

heroku run pip install gunicorn

它告诉我它成功地安装了gunicorn-19.3.0。但当我试着在Heroku上运行时

heroku run gunicorn

它向我发出了“bash:gunicorn:command not found”的消息。


Tags: tofrombashapp消息herokuwithnot
3条回答

只需将这一行添加到requirements.txt中

gunicorn==19.7.1

我就是这样解决的

gunicorn添加到requirements.txt

在寻找12-factor应用程序时,使用heroku run对文件系统所做的更改是ephemeral

我也遇到过同样的问题。
在做了一些研究之后,我发现这个tutorial他们解释说任何“本地”更改(比如导入/使用新模块)都必须使用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

相关问题 更多 >