我以前在PHP中使用过Heroku,但这是我第一次在Python和Flask中使用Heroku。首先,我想创建一个简单的“Hello World”应用程序,然后上传一个更复杂的程序。因此,项目文件夹包含以下内容:一个“Hello World”Python脚本(称为Main.py):from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html", message="Hello World")
if __name__ == "__main__":
app.run(debug=True)
一个templates文件,其中包含index.html文件(见上文)
一个runtime.txt文件:python-3.6.5
一个requirements.txt文件:Flask==1.0.1
(项目最初位于/Users/User/PycharmProjects/Project_HelloWorld。)
但是,当我在终端输入git push heroku master时,我得到了以下错误:Counting objects: 85, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (82/82), done.
Writing objects: 100% (85/85), 5.01 MiB | 3.13 MiB/s, done.
Total 85 (delta 24), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: ! The latest version of Python 3 is python-3.6.5 (you are using {\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf200
remote: {\fonttbl\f0\fmodern\fcharset0 Courier;}
remote: {\colortbl;\red255\green255\blue255;\red43\green47\blue49;\red237\green237\blue244;}
remote: {\*\expandedcolortbl;;\cssrgb\c21961\c24314\c25098;\cssrgb\c94510\c94510\c96471;}
remote: \paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
remote: \deftab720
remote: \pard\pardeftab720\partightenfactor0
remote:
remote: \f0\fs26 \cf2 \cb3 \expnd0\expndtw0\kerning0
remote: python-3.6.5}, which is unsupported).
remote: ! We recommend upgrading by specifying the latest version (python-3.6.5).
remote: Learn More: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> Installing {\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf200
remote: {\fonttbl\f0\fmodern\fcharset0 Courier;}
remote: {\colortbl;\red255\green255\blue255;\red43\green47\blue49;\red237\green237\blue244;}
remote: {\*\expandedcolortbl;;\cssrgb\c21961\c24314\c25098;\cssrgb\c94510\c94510\c96471;}
remote: \paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
remote: \deftab720
remote: \pard\pardeftab720\partightenfactor0
remote:
remote: \f0\fs26 \cf2 \cb3 \expnd0\expndtw0\kerning0
remote: python-3.6.5}
remote: ! Requested runtime ({\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf200
remote: {\fonttbl\f0\fmodern\fcharset0 Courier;}
remote: {\colortbl;\red255\green255\blue255;\red43\green47\blue49;\red237\green237\blue244;}
remote: {\*\expandedcolortbl;;\cssrgb\c21961\c24314\c25098;\cssrgb\c94510\c94510\c96471;}
remote: \paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
remote: \deftab720
remote: \pard\pardeftab720\partightenfactor0
remote:
remote: \f0\fs26 \cf2 \cb3 \expnd0\expndtw0\kerning0
remote: python-3.6.5}) is not available for this stack (heroku-16).
remote: ! Aborting. More info: https://devcenter.heroku.com/articles/python-support
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to evening-sierra-26101.
remote:
To https://git.heroku.com/evening-sierra-26101.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/evening-sierra-26101.git'
如何修复此错误并在Heroku上正确运行应用程序?
同样,当我在终端为上面的runtime.txt输入cat runtime.txt时,我得到了以下结果(非常意外?)输出:{\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf200
{\fonttbl\f0\fmodern\fcharset0 Courier;}
{\colortbl;\red255\green255\blue255;\red43\green47\blue49;\red237\green237\blue244;}
{\*\expandedcolortbl;;\cssrgb\c21961\c24314\c25098;\cssrgb\c94510\c94510\c96471;}
\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\deftab720
\pard\pardeftab720\partightenfactor0
\f0\fs26 \cf2 \cb3 \expnd0\expndtw0\kerning0
python-3.6.5}%
我首先在runtime.txt中使用python-3.6.4(而不是python-3.6.5)进行了尝试,但是我得到了相同的错误。在