【问题标题】:heroku: no default language could be detected for this appheroku:无法检测到此应用的默认语言
【发布时间】:2017-02-13 21:30:00
【问题描述】:

第一次使用 Heroku。试图推。我已经运行了命令:

heroku create --buildpack heroku/python

它显示出来了

$ 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

堆栈跟踪:

$ 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'

我一定是错过了什么。

我已将requirements.txt 添加到我的根目录。它看起来像这样:

.git
.idea
projectapp
projectname
rango
db.sqlite3
manage.py
populate_rango.py
requirements.txt

【问题讨论】:

    标签: python heroku


    【解决方案1】:

    今天遇到这个问题并发布了我将我的requirements.txt 命名为requirements.txt.txt(当它已经是一个文本文件时,我将文件命名为.txt 扩展名),我还有一个包含内容的runtime.txt 文件python-3.8.7.

    重命名 requirements.txt 文件正确解决了我的问题。

    我的根文件夹中有 3 个文件:code.py、requirements.txt 和 runtime.txt

    【讨论】:

      【解决方案2】:

      我正在运行一个 django 项目,但对我来说,上述解决方案均无效。所以最后我放弃了,去了错误中提到的路径,它清楚地表明 heroku 需要以下任一文件来检测 django 项目:

      1. requirements.txt
      2. setup.py
      3. 点文件

      我通过将 pip freeze 的内容复制到项目的根目录中创建了一个 requirements.txt 文件,它可以正常工作。

      【讨论】:

        【解决方案3】:

        在我的情况下,我在一个子 git 文件夹中。当我查看根 .git 文件夹时 - 该项目确实没有 package.json 文件 - 所以 heroku 无法识别 webpack

        【讨论】:

          【解决方案4】:

          如果您尝试了上述一些答案,但问题仍然存在;

          确保您在正确的目录中git“提交”。

          例如,如果你的文件结构如下:

          /src
              /...
              manage.py
          .gitignore
          Pipfile/requirements.txt
          Pipfile.lock
          Procfile
          runtime.txt
          

          确保您是 git 从根目录添加、提交、推送等。由于我们主要在src/main_app_directory/ 中工作,因此我们往往会忘记在提交之前将目录改回根目录。

          【讨论】:

            【解决方案5】:

            快速解决方案

            1. 转到 heroku 仪表板 (https://dashboard.heroku.com/)
            2. 进入应用程序/项目
            3. 点击设置
            4. 向下滚动一点并单击添加构建包
            5. 选择你想要的 buildpack(在我的例子中,我选择了 heroku/nodejs)。

            TLDR;

            实际上heroku所做的是,它试图通过查看项目中的文件来识别你正在部署的项目,例如如果你的项目有package.json文件,它就会理解它是一个nodejs项目,如果你的项目有@987654324 @file 它知道它是一个 python 项目等等,请参阅 this document 以了解您可以在 heroku 服务器上运行哪些语言

            如您所知,在计算机节点运行时中运行特定项目(例如 nodejs 项目)必须安装在该计算机中,否则您无法在计算机中安装 nodejs 应用程序,heroku 的作用是在不同的容器中运行您的每个应用程序,这意味着在一个容器中只有一个应用程序在运行,当然该容器已经安装了 nodejs,所以如果一个容器只运行一个应用程序,那么在容器中安装所有其他运行时是没有意义的,所以容器在我的容器中只有一个运行时如果是nodejs。他们当然有其他类型的容器,例如python的一种类型,并且该容器已经安装了python运行时(特定版本),所以如果我的应用程序安装在python容器中,它将无法工作,因为我的应用程序在nodejs中。出于这个原因,我们需要在开始选择正确的容器类型时识别应用程序的类型,主要是 heroku 自动检测它,但如果它未能检测到,您必须通过转到他们的仪表板设置或通过运行时文件明确告知您的项目,并且您可能已经注意到您只执行过一次。

            【讨论】:

            • 谢谢,我将需求文件命名为requierments.text,所以出现了错误。
            • @VishnuVS 它是 requirements.txt(而不是 requierments.text)检查拼写和文件扩展名
            【解决方案6】:

            使用Docker部署时,确保将应用的堆栈设置为container,如docs所示:

            heroku stack:set container
            

            【讨论】:

              【解决方案7】:

              还有一点需要注意的是,在将更改推送到 Heroku 之前,将更改实际提交到 git 存储库。 您可能在本地设置了 requirements.txt,但如果它没有提交到您的 repo,git push heroku master 将无法找到它。

              【讨论】:

                【解决方案8】:

                为了将来的参考,您必须确保将带有代码的分支推送到heroku master

                如果您从 master 分支分支,并且所有代码都在 develop 上,请将其推送到 heroku master。

                所以而不是:

                git push heroku master
                

                你会做这样的事情:

                git push heroku develop:master
                

                这个问题有关于这个How to push different local Git branches to Heroku/master的重要细节

                【讨论】:

                  【解决方案9】:

                  即使在包含 runtime.txt 之后,我也遇到了同样的问题。起作用的是包含 requirements.txt

                  【讨论】:

                  • 相同。只要将 requirements.txt 包含在 git repo 中并推送,它就可以正常工作
                  • 我同时拥有 requirments.txt 和 runtime.txt,但它无法正常工作...有什么提示吗?
                  • 我面临同样的问题@makewhite。你找到解决办法了吗?
                  【解决方案10】:

                  在根文件夹中创建Pipfile文件,并添加python version和应用程序所需的包。 check sample file here

                  [[source]]
                  
                  url = "https://pypi.python.org/simple"
                  verify_ssl = true
                  
                  
                  [packages]
                  
                  django = "*"
                  gunicorn = "*"
                  django-heroku = "*"
                  
                  
                  [requires]
                  
                  python_version = "3.6"
                  

                  同时检查Configuring Django Apps for Heroku

                  【讨论】:

                    【解决方案11】:

                    我不记得我是如何解决这个问题的,但是在我发布这个问题后查看文件中的 Date Modified 我创建了两个文件:

                    runtime.txt(感谢rurp)其中包含:

                    python-3.5.2
                    

                    Procfile 其中包含:

                    web: gunicorn projectname.wsgi --log-file -
                    

                    这是一个 Django 项目,projectname.wsgi 导致wsgi.py 位于

                    projectname/wsgi.py

                    这包含:

                    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)
                    

                    【讨论】:

                      【解决方案12】:

                      Heroku 的 Python 支持扩展到 Python 2.x 和 Python 3.x 系列的最新稳定版本。 今天,这种支持扩展到了这些特定的运行时:

                      • python-2.7.13
                      • python-3.6.1

                      尝试在 runtime.txt 中更改您的 python 版本

                      【讨论】:

                        【解决方案13】:

                        您需要创建一个 runtime.txt 文件。在命令行上,在您的 requirements.txt 文件所在的文件夹中,输入 echo "python-3.5.1" > runtime.txt。当然,请确保将 3.5.1 切换到您使用的任何 Python 版本。

                        【讨论】:

                        • 我有同样的问题,即使我有一个runtime.txt 文件。
                        猜你喜欢
                        • 1970-01-01
                        • 2017-10-29
                        • 2020-12-22
                        • 2021-11-12
                        • 2017-09-07
                        • 2018-02-22
                        • 2017-05-16
                        • 2018-07-13
                        相关资源
                        最近更新 更多