[英]Uploading a Django project on Heroku Server
I uploaded my Django project to Heroku and I get this error message on the browser as shown on the screenshot我将我的 Django 项目上传到 Heroku,我在浏览器上收到此错误消息,如屏幕截图所示
But when I check the log on the admin I see this message below:但是当我检查管理员的日志时,我看到下面这条消息:
2019-05-14T21:26:26.138333+00:00 app[web.1]: bash: gunicorn: command not found
2019-05-14T21:26:26.138333+00:00 app[web.1]: bash: gunicorn: command not found
But gunicorn
is included in my requirements.txt
file:但是
gunicorn
包含在我的requirements.txt
文件中:
dj-database-url==0.5.0
Django==2.2.1
django-heroku==0.3.1
gunicorn==19.9.0
psycopg2==2.8.2
pytz==2019.1
sqlparse==0.3.0
whitenoise==4.1.2
I also have a Pipfile
and Pipfile.lock
.我还有一个
Pipfile
和Pipfile.lock
。
Why can't Heroku find gunicorn
?为什么 Heroku 找不到
gunicorn
?
Generally speaking, you should use either requirements.txt
or Pipfile
and Pipfile.lock
.一般来说,您应该使用
requirements.txt
或Pipfile
和Pipfile.lock
。 They do roughly the same thing, but work with different tooling.他们做大致相同的事情,但使用不同的工具。
Pipfile
and Pipfile.lock
are a newer standard. Pipfile
和Pipfile.lock
是较新的标准。 If they are present, Heroku installs dependencies using Pipenv .如果它们存在,Heroku 会使用Pipenv安装依赖项。 In this case the
requirements.txt
file is ignored.在这种情况下,
requirements.txt
文件将被忽略。
You should either你应该
Choose to use Pipenv.选择使用 Pipenv。
Pipfile
and Pipfile.lock
, but run pipenv install -r requirements.txt
locally just to be sure.Pipfile
和Pipfile.lock
中,但为了确定起见,请在本地运行pipenv install -r requirements.txt
。requirements.txt
with git rm requirements.txt
.git rm requirements.txt
requirements.txt
git commit -m 'Switch from pip to Pipenv'
.git commit -m 'Switch from pip to Pipenv'
。 Choose to use pip
.选择使用
pip
。
Read your Pipfile
to see if there's anything in there you might need.阅读你的
Pipfile
看看里面是否有你可能需要的东西。 This file does more than just list dependencies.该文件不仅仅列出依赖项。
For example, your Pipfile
may specify a required Python version like python_version = '3.7'
in the [requires]
section.例如,您的
Pipfile
可能会在[requires]
部分指定所需的 Python 版本,如python_version = '3.7'
。 This can't be represented in requirements.txt
, so you'll need to create a runtime.txt
file to specify your Python version.这不能在
requirements.txt
中表示,因此您需要创建一个runtime.txt
文件来指定您的 Python 版本。
You might also want to create a second requirements file for development dependencies.您可能还想为开发依赖项创建第二个需求文件。
Delete the Pipfile
and Pipfile.lock
with git rm Pipfile Pipfile.lock
.使用
git rm Pipfile Pipfile.lock
删除Pipfile
和Pipfile.lock
。
Commit, eg git commit -m 'Revert from Pipenv to pip
.提交,例如
git commit -m 'Revert from Pipenv to pip
。
Push to Heroku.推送到 Heroku。
I uploaded my Django project to Heroku and I get this error message on the browser as shown on the screenshot我将我的 Django 项目上传到 Heroku,我在浏览器上收到此错误消息,如屏幕截图所示
But when I check the log on the admin I see this message below:但是当我检查管理员的日志时,我看到以下消息:
2019-05-14T21:26:26.138333+00:00 app[web.1]: bash: gunicorn: command not found
2019-05-14T21:26:26.138333+00:00 app[web.1]: bash: gunicorn: 命令未找到
But gunicorn
is included in my requirements.txt
file:但是
gunicorn
包含在我的requirements.txt
文件中:
dj-database-url==0.5.0
Django==2.2.1
django-heroku==0.3.1
gunicorn==19.9.0
psycopg2==2.8.2
pytz==2019.1
sqlparse==0.3.0
whitenoise==4.1.2
I also have a Pipfile
and Pipfile.lock
.我也有一个
Pipfile
和Pipfile.lock
。
Why can't Heroku find gunicorn
?为什么 Heroku 找不到
gunicorn
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.