Python 赫罗库可以';找不到gunicorn命令
我想在Heroku上安装一个小烧瓶应用程序。当它启动时,它会从日志中给我以下消息:Python 赫罗库可以';找不到gunicorn命令,python,heroku,flask,gunicorn,Python,Heroku,Flask,Gunicorn,我想在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.8636
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”消息。将
gunicorn
添加到requirements.txt
在开发应用程序时,使用heroku run对文件系统所做的更改非常重要。只需将这一行添加到您的requirements.txt中即可
gunicorn==19.7.1
我就是这样解决的我遇到了同样的问题。
在做了一些研究之后,我发现他们解释说任何“本地”更改(如导入/使用新模块)都必须使用pipenv“安装”在heroku应用程序中。 所以在这种情况下,我所做的是:
$ pipenv install gunicorn
这将在你的应用程序中“安装”gunicorn,并在你的(或创建一个新的)PIP文件中添加一个条目,这就是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
我在运行Ubuntu18.04.2 LTS仿生版时遇到了这个问题。解决方案是更新我的PATH变量 在~/.profile I中添加了以下行:
if [ -d "$HOME/.local" ] ; then
PATH="$HOME/.local:$PATH"
fi
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
我更改了“runtime.txt”以匹配我的Python3版本。我不确定这是否必要,但现在是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