Heroku找不到gunicorn命令

时间:2015-03-11 01:21:29

标签: python heroku flask gunicorn

我试图在Heroku上放一个小的Flask应用程序。当它启动时,它会从日志中给我以下消息:

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是我想要运行的文件。我查了一下这个问题,发现它有时是由gunicorn不在requirements.txt引起的,但是我的requirements.txt有它,用这行:

gunicorn==19.3.0

。 我试过跑

heroku run pip install gunicorn

它告诉我它成功安装了gunicorn-19.3.0。但是当我尝试用Heroku运行它时

heroku run gunicorn
反对它给了我" bash:gunicorn:命令未找到"消息。

5 个答案:

答案 0 :(得分:1)

只需将此行添加到 requirements.txt

即可
gunicorn==19.7.1

我是如何解决它的

答案 1 :(得分:0)

gunicorn添加到requirements.txt

在追求12-factor个应用时,使用heroku run对文件系统所做的更改为ephemeral

答案 2 :(得分:0)

我遇到了同样的问题 在做了一些研究后,我发现了tutorial,他们在那里解释了任何" local"更改(如导入/使用新模块)必须"安装"在使用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

答案 3 :(得分:0)

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

在〜/ .profile中,添加了以下行:

{
  "Reset Password Notification": "Viața Medicală CMS :: Resetare parolă",
  "Hello!": "Salut,",
  "You are receiving this email because we received a password reset request for your account.": "Primești acest email deoarece am primit o solicitare de resetare a parolei pentru contul tău.",
  "Reset Password": "Reseteză parola",
  "This password reset link will expire in :count minutes.": "Acest link va expira în :count de minute.",
  "If you did not request a password reset, no further action is required.": "Dacă nu ai solicitat resetarea parolei, nu este necesară nicio altă acțiune.",
  "Regards": "Toate cele bune",
  "Oh no": "O, nu",
  "Whoops!": "Hopa!",
  "If you’re having trouble clicking the \":actionText\" button, copy and paste the URL below\ninto your web browser: [:actionURL](:actionURL)": "Dacă nu reușești să dai click pe butonul de \":actionText\", dă copy-paste la URL-ul de mai jos în browser:\n [:actionURL](:actionURL)"
}

我更改了“ runtime.txt”以匹配我的Python 3版本。我不确定是否有必要,但是现在是if [ -d "$HOME/.local" ] ; then PATH="$HOME/.local:$PATH" fi if [ -d "$HOME/.local/bin" ] ; then PATH="$HOME/.local/bin:$PATH" fi

此外,因为我安装了各种版本的python和pip,所以我在本地安装和运行的命令是:

python-3.6.7

答案 4 :(得分:0)

这是一个清单:

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

  2. 从 Heroku 和您的本地环境中删除 PipfilePipfile.lock。只需保留 requirements.txt