Heroku + gunicorn无法正常工作(bash:gunicorn:命令未找到)

86

我成功安装了gunicorn:

remote: -----> Removing .DS_Store files
remote: -----> Python app detected
remote: -----> Installing dependencies with pip
remote:        Collecting gunicorn==19.0.0 (from -r requirements.txt (line 1))
remote:          Downloading gunicorn-19.0.0.tar.gz (382kB)
remote:        Installing collected packages: gunicorn
remote:          Running setup.py install for gunicorn
remote:        Successfully installed gunicorn-19.0.0

我的 Procfile:

web: gunicorn myapp:app --log-file=-

但是应用程序在部署时崩溃:

bash: gunicorn: command not found 

我尝试添加Heroku Python Buildpack,但没有成功。如果我回滚到以前的提交(其中requirements.txtProcfile都没有更改),它可以工作:

heroku/web.1:  Starting process with command `gunicorn myapp:app --log-file=-` 
app/web.1:  2015-10-08 17:04:18 [3] [INFO] Listening at: http://0.0.0.0:51854 (3)
19个回答

141

确保在你的 requirements.txt 文件中包含 gunicorn


4
我看到了你问题中的 remote: Collecting gunicorn==19.0.0 (from -r requirements.txt (line 1))。谢谢你的回复。 - maxko87
尝试在Heroku上重新创建您的应用程序。 - Quanlong
我重新创建了它,问题依旧。 - maxko87

22

在远程卸载所有依赖项并重新安装后,这个问题似乎自行解决了。


3
部署一个空的 requirements 文件,然后再部署原始版本的文件。 - maxko87
一个空的需求文件会给我带来这样的提示:"您必须至少提供一个要安装的需求(请参阅“pip help install”)"。 - Patrice Gagnon
5
这个解决方案真是晦涩难懂! - Mr.Pacman
1
@maxko87 你说得对,清空需求确实可以构建应用程序,但在我的情况下,当推送完整需求时,它仍然会崩溃。 - Revolucion for Monica
1
@maxko87,你能在回答中具体说明一下如何远程卸载依赖吗? - hp77
显示剩余2条评论

17

我缺少 heroku/python buildpack,因此我去了仪表板并执行了以下操作:

Settings -> Add buildpack -> heroku/python

15

在您的虚拟环境中安装gunicorn

pip install gunicorn

然后更新您的requirements.txt文件

pip freeze > requirements.txt

我转向诗歌,并忘记安装gunicorn,因为它只在部署时相关。 - moto

12
如果你的项目根目录中同时有requirements.txt和Pipfile这两个文件,我建议你删除Pipfile并将所有的依赖都列在requirements.txt文件中(包括gunicorn)。
这样做将显示:"Installing requirements from pip",并且requirements.txt中列出的所有依赖项都将被安装。

4

Heroku的Python文档似乎已经过时了... 显然现在他们更喜欢使用 Pipfile 而不是requirements.txt,但令人欣慰的是,您可以轻松用 pipenv 生成一个。

试试这个:

$ pip3 install --user pipenv 安装 pipenv

$ pipenv install gunicorn 将gunicorn添加到pipfile中

$ pipenv shell 激活虚拟环境

我遇到了完全相同的错误,这对我很有用!


2
在我的情况下,存在冲突,因为我在同一个目录/项目中同时拥有PipfilePipfile.lockrequirements.txt文件。由于Heroku没有从requirements.txt安装任何内容,因此出现了与所有人都遇到的相同的gunicorn错误。

2

在确认 requirements.txt 中包含了 gunicorn 后,运行以下命令:

最初的回答:

pip install -r requirements.txt

我的输出包含了几个Requirement already satisfied: ...,但是gunicorn没有被安装:

最初的回答:

Collecting gunicorn (from -r requirements.txt (line 2))
Using cached ...

Installing collected packages: gunicorn
Successfully installed gunicorn-19.9.0

1

在requirements.txt中添加gunicorn解决了我的问题。


1
在我的情况下,虽然requirements.txt中有gunicorn,但由于存在Pipfile,gunicorn未被安装。我从github存储库中删除了Pipfile并成功重新部署。
以下简短的教程也很有帮助,以确保我正确配置了runtime.txt、wsgi.py和Procfile的要点。

https://www.geeksforgeeks.org/deploy-python-flask-app-on-heroku/


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