Python heroku:无法检测到此应用程序的默认语言
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39873920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
heroku: no default language could be detected for this app
提问by Josh Laird
First time using Heroku. Trying to push. I have run the command:
第一次使用 Heroku。试图推动。我已经运行了命令:
heroku create --buildpack heroku/python
heroku create --buildpack heroku/python
and it displayed
它显示
$ heroku create --buildpack heroku/python
Creating app... done, glacial-reef-7599
Setting buildpack to heroku/python... done
https://glacial-reef-7599.herokuapp.com/ | https://git.heroku.com/glacial-reef-7599.git
Stack trace:
堆栈跟踪:
$ git push heroku master
Counting objects: 129, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (124/124), done.
Writing objects: 100% (129/129), 69.06 KiB | 0 bytes/s, done.
Total 129 (delta 22), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: ! No default language could be detected for this app.
remote: HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
remote: See https://devcenter.heroku.com/articles/buildpacks
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to pure-badlands-9125.
remote:
To https://git.heroku.com/pure-badlands-9125.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/pure-badlands-9125.git'
I've gotta be missing something.
我一定错过了一些东西。
I have added a requirements.txt
to my root directory. It looks like this:
我已经requirements.txt
在我的根目录中添加了一个。它看起来像这样:
.git
.idea
projectapp
projectname
rango
db.sqlite3
manage.py
populate_rango.py
requirements.txt
采纳答案by Josh Laird
I can't remember how I fixed this but looking at the Date Modified
in my files after I posted this question I created two files:
我不记得我是如何解决这个问题的,但是Date Modified
在我发布这个问题后查看我的文件中的我创建了两个文件:
runtime.txt
(thanks rurp) which contains:
runtime.txt
(感谢rupp)其中包含:
python-3.5.2
Procfile
which contains:
Procfile
其中包含:
web: gunicorn projectname.wsgi --log-file -
This is a Django project and projectname.wsgi
leads to a wsgi.py
located at
这是一个 Django 项目并projectname.wsgi
导致wsgi.py
位于
projectname/wsgi.py
projectname/wsgi.py
This contains:
这包含:
import os
import signal
import sys
import traceback
import time
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "projectname.settings")
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
回答by willieswanjala
For future references, you must ensure that you are pushing the branch with your code to heroku master
.
为了将来参考,您必须确保将带有代码的分支推送到heroku master
.
If you branched from your master
branch and all your code is on a, say, develop
, push that to the heroku master.
如果你从你的master
分支分支并且你的所有代码都在一个,比如说develop
,把它推送到 heroku master。
So instead of:
所以而不是:
git push heroku master
You would do something like:
你会做这样的事情:
git push heroku develop:master
This question has important details on this How to push different local Git branches to Heroku/master
这个问题有关于这个如何将不同的本地 Git 分支推送到 Heroku/master 的重要细节
回答by rurp
You need to create a runtime.txt file. On the command line, in the same folder as your requirements.txt file, enter echo "python-3.5.1" > runtime.txt
. Of course, make sure to switch the 3.5.1 with whichever version of Python you are using.
您需要创建一个 runtime.txt 文件。在命令行上,在您的 requirements.txt 文件所在的文件夹中,输入echo "python-3.5.1" > runtime.txt
. 当然,请确保将 3.5.1 与您使用的任何版本的 Python 切换。
回答by Inzamam Malik
Quick Solution
快速解决方案
- Goto heroku dashboard(https://dashboard.heroku.com/)
- go inside app/project
- click setting
- scroll down little bit and click add build pack
- select your desired buildpack(in my case i have selected heroku/nodejs).
- 转到heroku 仪表板( https://dashboard.heroku.com/)
- 进入应用程序/项目
- 点击设置
- 向下滚动一点,然后单击添加构建包
- 选择你想要的 buildpack(在我的例子中我选择了 heroku/nodejs)。
TLDR;
TLDR;
Actually what heroku does is, it tries to identify what project you are deploying by looking at files in your project, such as if your project have package.json
file it understands it is a nodejs project, if your project have requirements.txt
file it understands it is a python project and so on, see this documentto see to know what languages you can run on a heroku server
实际上heroku所做的是,它试图通过查看项目中的文件来确定您正在部署的项目,例如,如果您的项目有package.json
文件,则它理解为nodejs项目,如果您的项目有requirements.txt
文件,则它理解为python项目等等,请参阅此文档以了解您可以在 heroku 服务器上运行哪些语言
as you know to run a specific project such as a nodejs project in a computer node runtime must be installed in that computer otherwise you can not nodejs app in the computer, what heroku does it runs each of your app in a different container, it means in one container it is only one app is running and of course that container have installed nodejs, so if a container runs only one app it doesnt make sense to install all other runtimes in the container so container have only one runtime in my case it is nodejs. they have ofcourse other type of containers such as one type for python and that container have installed python runtime(of a specific version) so if my app gets installed in python container it will not work because my app in in nodejs. for this very reason somehow we need to identify the type of app in beginning to choose correct container type, mostly heroku automatically detect it but if it is failed to detect you have to tell explicitly either by going to their dashboard settings or through runtime file in your project, and as you may have noticed you have do this only once.
如您所知,在计算机节点运行时中运行特定项目(例如 nodejs 项目)必须安装在该计算机中,否则您无法在计算机中使用 nodejs 应用程序,heroku 是做什么的,它将您的每个应用程序运行在不同的容器中,这意味着在一个容器中只有一个应用程序正在运行,当然该容器已经安装了 nodejs,所以如果一个容器只运行一个应用程序,那么在容器中安装所有其他运行时是没有意义的,所以在我的情况下容器只有一个运行时节点。他们当然有其他类型的容器,例如 python 的一种类型,并且该容器已经安装了 python 运行时(特定版本),因此如果我的应用程序安装在 python 容器中,它将无法工作,因为我的应用程序在 nodejs 中。
回答by user7217806
回答by TsaiKoga
Heroku's Python support extends to the latest stable release from the Python 2.x and Python 3.x series. Today, this support extends to these specific runtimes:
Heroku 的 Python 支持扩展到 Python 2.x 和 Python 3.x 系列的最新稳定版本。今天,这种支持扩展到这些特定的运行时:
- python-2.7.13
- python-3.6.1
- python-2.7.13
- python-3.6.1
try to change your python version in runtime.txt
尝试在 runtime.txt 中更改您的 python 版本
回答by Indi
I had the same problem even after including runtime.txt. What worked was the inclusion of the requirements.txt
即使在包含 runtime.txt 之后,我也遇到了同样的问题。有效的是包含requirements.txt
回答by kartheek
Create Pipfilefile in root folder and add python version
and packages required for application. check sample file here
在根文件夹中创建Pipfile文件并添加python version
应用程序所需的包。在此处检查示例文件
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
[packages]
django = "*"
gunicorn = "*"
django-heroku = "*"
[requires]
python_version = "3.6"
Also check Configuring Django Apps for Heroku
回答by Olamigoke Philip
If you've tried some of the above answers and the problem still persists;
如果您已经尝试了上面的一些答案,但问题仍然存在;
Ensure you are git
"committing" in the right directory.
确保您git
在正确的目录中“提交”。
For instance, if your file structure is as follow:
例如,如果您的文件结构如下:
/src
/...
manage.py
.gitignore
Pipfile/requirements.txt
Pipfile.lock
Procfile
runtime.txt
Ensure you're git
adding, committing, pushing etc. from the root directory. Since we work mostly in the src/
or main_app_directory/
we tend to forget to change directory back to root before committing.
确保您git
从根目录添加、提交、推送等。由于我们主要在src/
或main_app_directory/
我们往往忘记在提交之前将目录更改回根目录。
回答by litpumpk1n
One more thing to note is to actually commit your changes to your git repo, before you can push them to Heroku.
You might have a requirements.txt setup locally, but if it's not committed to your repo, git push heroku master
will not be able to locate it.
需要注意的另一件事是,在将更改推送到 Heroku 之前,将更改实际提交到 git 存储库。你可能在本地有一个 requirements.txt 设置,但如果它没有提交到你的仓库,git push heroku master
将无法找到它。