在heroku上部署django网站时出错
Posted
技术标签:
【中文标题】在heroku上部署django网站时出错【英文标题】:Error in deploying django website on heroku 【发布时间】:2015-04-28 15:52:38 【问题描述】:我在 django 的 setting.py 文件中使用 DATABASE = 在 heroku 中部署我的 django 网站。 我正在遵循heroku help 的所有步骤,并且每个命令都运行 但是运行命令时出现了一些应用程序错误-
heroku 打开
(jango)dc@dc-comp-4:~/website$ heroku open
Opening evening-waters-7886... done
(jango)dc@dc-comp-4:~/website$
(process:8176): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed
我的heroku日志状态是-
dc@dc-comp-4:~/website$ heroku logs
2015-02-26T09:07:09.555685+00:00 heroku[web.1]: State changed from crashed to starting
2015-02-26T09:07:09.555087+00:00 heroku[web.1]: State changed from starting to crashed
2015-02-26T09:07:17.890143+00:00 heroku[web.1]: Starting process with command `gunicorn gettingstarted.wsgi --log-file -`
2015-02-26T09:07:20.325197+00:00 app[web.1]: bash: gunicorn: command not found
2015-02-26T09:07:21.184736+00:00 heroku[web.1]: Process exited with status 127
2015-02-26T09:07:21.202490+00:00 heroku[web.1]: State changed from starting to crashed
2015-02-26T09:07:27.250898+00:00 heroku[api]: Scale to web=1 by rahulsatal92@gmail.com
2015-02-26T09:07:56.156898+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=evening-waters-7886.herokuapp.com request_id=9a9781c5-57d6-43c2-8ca0-43df571804a0 fwd="14.139.240.226" dyno= connect= service= status=503 bytes=
2015-02-26T09:08:01.602067+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=evening-waters-7886.herokuapp.com request_id=597a1c36-200e-4f8c-8dfe-b00d4d2cacee fwd="14.139.240.226" dyno= connect= service= status=503 bytes=
2015-02-26T09:08:03.737046+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=evening-waters-7886.herokuapp.com request_id=4d790108-6019-4fce-9d1e-10eafca9efc1 fwd="14.139.240.226" dyno= connect= service= status=503 bytes=
2015-02-26T09:27:54.099907+00:00 heroku[api]: Deploy e061461 by rahulsatal92@gmail.com
2015-02-26T09:27:54.099907+00:00 heroku[api]: Release v6 created by rahulsatal92@gmail.com
2015-02-26T09:27:54.255144+00:00 heroku[web.1]: State changed from crashed to starting
2015-02-26T09:28:05.720678+00:00 heroku[web.1]: Starting process with command `gunicorn website:app --log-file=-`
2015-02-26T09:28:06.984648+00:00 app[web.1]: bash: gunicorn: command not found
2015-02-26T09:28:07.736542+00:00 heroku[web.1]: State changed from starting to crashed
2015-02-26T09:28:07.737796+00:00 heroku[web.1]: State changed from crashed to starting
2015-02-26T09:28:07.721050+00:00 heroku[web.1]: Process exited with status 127
2015-02-26T09:28:11.784672+00:00 heroku[web.1]: Starting process with command `gunicorn website:app --log-file=-`
2015-02-26T09:28:13.765503+00:00 app[web.1]: bash: gunicorn: command not found
2015-02-26T09:28:14.689070+00:00 heroku[web.1]: Process exited with status 127
2015-02-26T09:28:14.702968+00:00 heroku[web.1]: State changed from starting to crashed
2015-02-26T09:28:18.234685+00:00 heroku[api]: Scale to web=1 by rahulsatal92@gmail.com
2015-02-26T09:28:48.532426+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=evening-waters-7886.herokuapp.com request_id=a2b76940-91ea-4d2d-884e-0049bc707217 fwd="14.139.240.226" dyno= connect= service= status=503 bytes=
2015-02-26T09:32:01.295019+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=evening-waters-7886.herokuapp.com request_id=7bf7ddc0-a04f-4f40-aade-f7a5116cf9f0 fwd="14.139.240.226" dyno= connect= service= status=503 bytes=
2015-02-26T09:34:29.437580+00:00 heroku[api]: Attach HEROKU_POSTGRESQL_BLUE resource by rahulsatal92@gmail.com
2015-02-26T09:34:29.437580+00:00 heroku[api]: Release v7 created by rahulsatal92@gmail.com
2015-02-26T09:34:29.678932+00:00 heroku[web.1]: State changed from crashed to starting
2015-02-26T09:34:33.288768+00:00 heroku[web.1]: Starting process with command `gunicorn website:app --log-file=-`
2015-02-26T09:34:35.045626+00:00 app[web.1]: bash: gunicorn: command not found
2015-02-26T09:34:35.717937+00:00 heroku[web.1]: Process exited with status 127
2015-02-26T09:34:35.729414+00:00 heroku[web.1]: State changed from starting to crashed
2015-02-26T09:39:47.384245+00:00 heroku[api]: Release v8 created by rahulsatal92@gmail.com
2015-02-26T09:39:47.384245+00:00 heroku[api]: Attach HEROKU_POSTGRESQL_OLIVE resource by rahulsatal92@gmail.com
2015-02-26T09:39:47.747151+00:00 heroku[web.1]: State changed from crashed to starting
2015-02-26T09:39:50.940581+00:00 heroku[web.1]: Starting process with command `gunicorn website:app --log-file=-`
2015-02-26T09:39:52.075160+00:00 app[web.1]: bash: gunicorn: command not found
2015-02-26T09:39:52.716034+00:00 heroku[web.1]: State changed from starting to crashed
2015-02-26T09:39:52.716772+00:00 heroku[web.1]: State changed from crashed to starting
2015-02-26T09:39:52.705237+00:00 heroku[web.1]: Process exited with status 127
2015-02-26T09:39:56.910325+00:00 heroku[web.1]: Starting process with command `gunicorn website:app --log-file=-`
2015-02-26T09:39:58.335235+00:00 app[web.1]: bash: gunicorn: command not found
2015-02-26T09:39:59.091134+00:00 heroku[web.1]: Process exited with status 127
2015-02-26T09:39:59.123230+00:00 heroku[web.1]: State changed from starting to crashed
2015-02-26T09:41:28.032235+00:00 heroku[api]: Deploy 5e882c5 by rahulsatal92@gmail.com
2015-02-26T09:41:28.032235+00:00 heroku[api]: Release v9 created by rahulsatal92@gmail.com
2015-02-26T09:41:28.577676+00:00 heroku[web.1]: State changed from crashed to starting
2015-02-26T09:41:32.256825+00:00 heroku[web.1]: Starting process with command `gunicorn website:app --log-file=-`
2015-02-26T09:41:33.437334+00:00 app[web.1]: bash: gunicorn: command not found
2015-02-26T09:41:34.121450+00:00 heroku[web.1]: Process exited with status 127
2015-02-26T09:41:34.126557+00:00 heroku[web.1]: State changed from starting to crashed
2015-02-26T09:41:46.438295+00:00 heroku[api]: Scale to web=1 by rahulsatal92@gmail.com
2015-02-26T09:42:04.929728+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=evening-waters-7886.herokuapp.com request_id=f16cebee-7c15-42d5-bba6-a4c85d0addaf fwd="14.139.240.226" dyno= connect= service= status=503 bytes=
2015-02-26T09:43:05.406941+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=evening-waters-7886.herokuapp.com request_id=9e4aa61d-073d-49d2-a696-606b4c965d51 fwd="14.139.240.226" dyno= connect= service= status=503 bytes=
2015-02-26T09:44:05.946147+00:00 heroku[api]: Attach HEROKU_POSTGRESQL_COPPER resource by rahulsatal92@gmail.com
2015-02-26T09:44:05.946147+00:00 heroku[api]: Release v10 created by rahulsatal92@gmail.com
2015-02-26T09:44:06.133499+00:00 heroku[web.1]: State changed from crashed to starting
2015-02-26T09:44:09.806610+00:00 heroku[web.1]: Starting process with command `gunicorn website:app --log-file=-`
2015-02-26T09:44:11.203036+00:00 app[web.1]: bash: gunicorn: command not found
2015-02-26T09:44:11.895235+00:00 heroku[web.1]: Process exited with status 127
2015-02-26T09:44:11.911573+00:00 heroku[web.1]: State changed from starting to crashed
2015-02-26T09:52:08.400443+00:00 heroku[api]: Scale to web=1 by rahulsatal92@gmail.com
2015-02-26T09:52:30.139203+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=evening-waters-7886.herokuapp.com request_id=2e818d74-a717-41d4-9050-3be25889eaed fwd="14.139.240.226" dyno= connect= service= status=503 bytes=
2015-02-26T09:58:07.383685+00:00 heroku[api]: Starting process with command `rake db:migrate` by rahulsatal92@gmail.com
2015-02-26T09:58:11.492711+00:00 heroku[run.3731]: Awaiting client
2015-02-26T09:58:11.520152+00:00 heroku[run.3731]: Starting process with command `rake db:migrate`
2015-02-26T09:58:13.489900+00:00 heroku[run.3731]: Process exited with status 127
2015-02-26T09:58:13.503789+00:00 heroku[run.3731]: State changed from up to complete
2015-02-26T09:58:11.931301+00:00 heroku[run.3731]: State changed from starting to up
2015-02-26T09:59:05.424832+00:00 heroku[web.1]: State changed from crashed to starting
2015-02-26T09:59:12.340999+00:00 heroku[web.1]: Starting process with command `gunicorn website:app --log-file=-`
2015-02-26T09:59:13.778095+00:00 app[web.1]: bash: gunicorn: command not found
2015-02-26T09:59:14.428734+00:00 heroku[web.1]: Process exited with status 127
2015-02-26T09:59:14.437924+00:00 heroku[web.1]: State changed from starting to crashed
2015-02-26T09:59:14.438617+00:00 heroku[web.1]: State changed from crashed to starting
2015-02-26T09:59:17.805847+00:00 heroku[web.1]: Starting process with command `gunicorn website:app --log-file=-`
2015-02-26T09:59:19.331755+00:00 app[web.1]: bash: gunicorn: command not found
2015-02-26T09:59:20.010738+00:00 heroku[web.1]: Process exited with status 127
2015-02-26T09:59:20.028996+00:00 heroku[web.1]: State changed from starting to crashed
2015-02-26T09:59:23.726010+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=evening-waters-7886.herokuapp.com request_id=c2ba4a6d-1357-47a4-abee-78cfe3db7545 fwd="14.139.240.226" dyno= connect= service= status=503 bytes=
2015-02-26T10:04:06.912448+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=evening-waters-7886.herokuapp.com request_id=5d21087f-d811-4685-964b-23acf24fd499 fwd="14.139.240.226" dyno= connect= service= status=503 bytes=
2015-02-26T10:29:10.000446+00:00 heroku[api]: Starting process with command `pip install gunicorn` by rahulsatal92@gmail.com
2015-02-26T10:29:13.833066+00:00 heroku[run.8299]: Awaiting client
2015-02-26T10:29:13.871544+00:00 heroku[run.8299]: Starting process with command `pip install gunicorn`
2015-02-26T10:29:14.121060+00:00 heroku[run.8299]: State changed from starting to up
2015-02-26T10:29:18.182526+00:00 heroku[run.8299]: Process exited with status 0
2015-02-26T10:29:18.195891+00:00 heroku[run.8299]: State changed from up to complete
2015-02-26T10:32:34.286827+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=evening-waters-7886.herokuapp.com request_id=29508561-6c27-4ac6-a67d-7543fb87b385 fwd="14.139.240.226" dyno= connect= service= status=503 bytes=
2015-02-26T10:36:58.977614+00:00 heroku[web.1]: State changed from crashed to starting
2015-02-26T10:37:02.450833+00:00 heroku[web.1]: Starting process with command `gunicorn website:app --log-file=-`
2015-02-26T10:37:03.717531+00:00 app[web.1]: bash: gunicorn: command not found
2015-02-26T10:37:04.438957+00:00 heroku[web.1]: State changed from starting to crashed
2015-02-26T10:37:04.439393+00:00 heroku[web.1]: State changed from crashed to starting
2015-02-26T10:37:04.418361+00:00 heroku[web.1]: Process exited with status 127
2015-02-26T10:37:08.015347+00:00 heroku[web.1]: Starting process with command `gunicorn website:app --log-file=-`
2015-02-26T10:37:09.728762+00:00 app[web.1]: bash: gunicorn: command not found
2015-02-26T10:37:10.601803+00:00 heroku[web.1]: State changed from starting to crashed
2015-02-26T10:37:10.596391+00:00 heroku[web.1]: Process exited with status 127
2015-02-26T11:21:32.653989+00:00 heroku[web.1]: State changed from crashed to starting
2015-02-26T11:21:36.340593+00:00 heroku[web.1]: Starting process with command `gunicorn website:app --log-file=-`
2015-02-26T11:23:39.380466+00:00 heroku[web.1]: State changed from starting to down
dc@dc-comp-4:~/website$ ^C
请帮帮我。
【问题讨论】:
【参考方案1】:bash: gunicorn: 找不到命令
上面的错误明确提到你在Heroku服务器上没有gunicorn
如何安装
-
使用
pip install gunicorn
安装它会清除错误。
将 gunicorn 添加到您的 requirements.txt 文件中
【讨论】:
在运行上面的命令时,我得到 - 要求已经满足(使用 --upgrade 升级):gunicorn in /home/dc/.virtualenvs/jango/lib/python2.7/site-packages 清理... @RahulSatal 更好的调试方式,您可以登录 heroku bash 并运行pip freeze
以确保 gunicorn
吗?或尝试heroku run pip install gunicorn
是的,它包含 gunicorn==17.5 和 command-heroku run pip install gunicorn ,安装成功
@RahulSatal 没有先生,你能再粘贴一下heroku日志吗?
我已在问题中更新了我的 heroku 日志。请检查一下【参考方案2】:
您应该安装 django-toolbelt(您可以通过 pip install django-toolbelt
来安装),然后它会安装 gunicorn),然后您需要将其添加到您的 requirements.txt(使用 pip freeze > requirements.txt
)。
让我这样解释。 Heroku 查看您的文件结构并搜索两件事: 一个 Procfile 和一个 requirements.txt(如果你有一个 python 项目,如果你有其他项目,这个代表你项目依赖的文件的名称可能有另一个名称,但让我们坚持使用 python django)。
它使用 requirements.txt 的内容来查看需要安装的内容,如果我想要某个库,它需要在该 requirements.txt 中添加(heroku 将安装它知道应该安装的所有内容,并且它知道什么它应该通过查看 requirements.txt 来安装)
然后它查看 Procfile(这个文件告诉它应该运行什么来启动项目)
现在来到你的错误,你可以在那个 prof 文件中写入流动的东西
web: python manage.py runserver 0.0.0.0:$PORT
这意味着:启动一个网络测功机,运行以下命令并使用环境变量$PORT
提供的端口
这将使用测试服务器在本地主机上启动 django,以确保它可以正常工作。你不应该在生产中使用它,但调试是好的。
如果你不能让它与它一起工作,这意味着你还有其他问题,而不仅仅是失去了独角兽。
在heroku教程中有一段说:
接下来,使用 pip 安装我们应用程序的依赖项。在这种情况下,我们将安装 django-toolbelt,其中包括我们需要的所有包: Django(网络框架) Gunicorn(WSGI 服务器) dj-database-url(Django 配置助手) dj-static(一个 Django 静态文件服务器)
在此处粘贴您的 requirements.txt,以便我们更快地计算出来。
如果要在 heroku 上使用 Django,请使用 this 。
【讨论】:
唯一适合我的解决方案。非常感谢您如此详细的回复。以上是关于在heroku上部署django网站时出错的主要内容,如果未能解决你的问题,请参考以下文章
Django 'pip install django-heroku'(psycopg2) 错误阻止部署到 Heroku