简体   繁体   English

Heroku 找不到 gunicorn 命令

[英]Heroku can't find gunicorn command

I'm trying to put a small Flask app on Heroku.我正在尝试在 Heroku 上放置一个小型 Flask 应用程序。 When it starts, it gives me the following message, from the logs:当它启动时,它从日志中给我以下消息:

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

My Procfile is我的 Procfile 是

web: gunicorn application:app

, and application.py is the file I want to run. , application.py 是我要运行的文件。 I looked up this problem and saw that it was sometimes caused by gunicorn not being in requirements.txt, but my requirements.txt has it, with this line:我查了一下这个问题,发现它有时是由gunicorn不在requirements.txt中引起的,但我的requirements.txt有它,有这一行:

gunicorn==19.3.0

. . I tried running我试过跑步

heroku run pip install gunicorn

and it told me it installed gunicorn-19.3.0 successfully.它告诉我它成功安装了 gunicorn-19.3.0。 But when I tried running it on Heroku with但是当我尝试在 Heroku 上运行它时

heroku run gunicorn

it against gave me the "bash: gunicorn: command not found" message.它反对给了我“bash:gunicorn:找不到命令”消息。

Add gunicorn to requirements.txt .gunicorn添加到requirements.txt

In pursuit of 12-factor apps, changes to the filesystem made with heroku run are ephemeral .为了追求12-factor应用程序,使用heroku run对文件系统所做的更改是短暂的

I ran into this same issue.我遇到了同样的问题。
After doing some research, I found this tutorial where they explain that any "local" changes (like importing/using a new module) must be "installed" in the heroku app using pipenv.在做了一些研究之后,我发现了这个教程,他们解释说任何“本地”更改(例如导入/使用新模块)都必须使用 pipenv 在 heroku 应用程序中“安装”。 So in this case what I did was:所以在这种情况下,我所做的是:

$ pipenv install gunicorn

This will "install" gunicorn in you app and add an entry into your (or create a new) Pipfile, which is how Heroku keeps track of the dependencies it needs to install for your app (I believe the use of requirements.txt is still supported, but not what they recommend).这将在您的应用程序中“安装”gunicorn 并在您的(或创建一个新的)Pipfile 中添加一个条目,这就是 Heroku 跟踪它需要为您的应用程序安装的依赖项的方式(我相信 requirements.txt 的使用仍然是支持,但不是他们推荐的)。

Then, in order to 'activate' the pip environment that has gunicorn installed you must run:然后,为了“激活”安装了 gunicorn 的 pip 环境,您必须运行:

$ pipenv shell

NOTE: You can test whether it worked or not by running $ heroku local注意:您可以通过运行$ 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

With pip environment activated:启用 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

just add this line into your requirements.txt只需将此行添加到您的requirements.txt

gunicorn==19.7.1

that's how i fix it我就是这样解决的

I had this problem running Ubuntu 18.04.2 LTS bionic.我在运行 Ubuntu 18.04.2 LTS 仿生时遇到了这个问题。 The solution was to update my PATH variable!解决方案是更新我的 PATH 变量!

In ~/.profile I added the lines:在 ~/.profile 我添加了以下几行:

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

I changed the "runtime.txt" to match my version of Python 3. I'm not sure whether that was necessary, but now it is python-3.6.7我更改了“runtime.txt”以匹配我的 Python 3 版本。我不确定这是否有必要,但现在是python-3.6.7

Also, because I have various versions of python and pip installed, my commands to install and run locally were:另外,因为我安装了各种版本的 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

Here's a checklist:这是一个清单:

  1. Install Gunicorn on your local environment and add it to the requirements.txt using pip freeze > requirements.txt .在本地环境中安装 Gunicorn 并使用pip freeze > requirements.txt将其添加到pip freeze > requirements.txt Commit the changes to Heroku.将更改提交到 Heroku。

  2. Remove Pipfile and Pipfile.lock from Heroku and your local environment.从 Heroku 和您的本地环境中删除PipfilePipfile.lock Just keep the requirements.txt .只需保留requirements.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM