简体   繁体   English

推送被拒绝,无法编译Python应用程序 - Python版本错误

[英]Push rejected, failed to compile Python app - Python version error

I have used Heroku with PHP in the past but this is the first time I am using Heroku with Python and Flask. 我过去使用过Heroku和PHP,但这是我第一次使用Heroku和Python和Flask。 For start, I want to create a simple "Hello World" app and then upload a more complex program I have built. 首先,我想创建一个简单的“Hello World”应用程序,然后上传我构建的更复杂的程序。 Therefore the project's folder contains the following: 因此,项目的文件夹包含以下内容:

  • One "Hello World" Python script (called Main.py ): 一个“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) 
  • A templates file with a index.html file (see above) inside it 一个带有index.html文件的templates文件(见上文)

  • One runtime.txt file: 一个runtime.txt文件:

     python-3.6.5 
  • One requirements.txt file: 一个requirements.txt文件:

     Flask==1.0.1 

(The project is originally located at /Users/User/PycharmProjects/Project_HelloWorld .) (该项目最初位于/Users/User/PycharmProjects/Project_HelloWorld 。)

However, when I enter git push heroku master at the terminal then I am getting the following error: 但是,当我在终端输入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'

How can I fix this error and properly run my app on Heroku? 如何修复此错误并在Heroku上正确运行我的应用程序?

Also when I am entering cat runtime.txt at the terminal for the runtime.txt above then I am getting the following (quite unexpected?) output: 此外,当我在终端输入上面的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}%

I have firstly tried it with python-3.6.4 (instead of python-3.6.5) in the runtime.txt but I was getting the same error. 我首先在runtime.txt尝试使用python-3.6.4 (而不是python-3.6.5),但我得到了同样的错误。

First I'd figure out how to run your app with gunicorn, as that's the most common deployment server for Flask apps. 首先,我将弄清楚如何使用gunicorn运行您的应用程序,因为这是Flask应用程序最常用的部署服务器。 To run your app with gunicorn, you should be able to pip install gunicorn , then run from the root of your project: gunicorn my_file_name:app , where my_file_name == the name of the file that contains your Flask code above. 要使用gunicorn运行您的应用程序,您应该能够pip install gunicorn ,然后从项目的根目录运行: gunicorn my_file_name:app ,其中my_file_name ==包含上面Flask代码的文件的名称。 Eg if your Flask code is in a file named app.py, you'd run gunicorn app:app . 例如,如果您的Flask代码位于名为app.py的文件中,那么您将运行gunicorn app:app

Once you can run the app with gunicorn, create a Procfile that specifies you want Heroku to run the server with gunicorn. 一旦你可以使用gunicorn运行应用程序,创建一个Procfile,指定你希望Heroku运行带有gunicorn的服务器。 Here's the contents of Procfile , which should be in the root of your project files (the same directory with requirements.txt ): 这是Procfile的内容,它应该位于项目文件的根目录中(与requirements.txt相同的目录):

web: gunicorn app:app

Then I'd update requirements.txt . 然后我会更新requirements.txt Do a pip freeze | grep gunicorn pip freeze | grep gunicorn pip freeze | grep gunicorn to get your gunicorn version then add it to the requirements.txt file: pip freeze | grep gunicorn获取你的gunicorn版本,然后将其添加到requirements.txt文件:

Flask==1.0.1
gunicorn==19.7.1

Finally, to resolve the immediate cause of your error above, I'd set runtime.txt to: 最后,为了解决上述错误的直接原因,我将runtime.txt设置为:

python-3.6.4

Then git push heroku master should be able to get you going... 那么git push heroku master 应该可以让你去...

If all else fails, here's a simple repository that has a barebones Flask app with Heroku deployment instructions in the README. 如果所有其他方法都失败了, 这里有一个简单的存储库 ,它在README中有一个带有Heroku部署指令的准系统Flask应用程序。 It's deployed here: https://myapp-name-1.herokuapp.com/ 它部署在这里: https//myapp-name-1.herokuapp.com/

So I found what it was going wrong and now my "Hello World" can run properly on Heroku. 所以我发现它出了什么问题,现在我的“Hello World”可以在Heroku上正常运行。

The problem was the that even though I created anew the runtime.txt file and the requirements.txt for some reason the following "text" was inserted in them before the proper text: 问题是,即使我重新创建了runtime.txt文件和requirements.txt由于某种原因,在正确的文本之前插入了以下“text”:

\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

This was displayed at the error that I posted above when I was trying to do git push heroku master at my app and when I was entering cat runtime.txt . 当我在我的应用程序中尝试执行git push heroku master时以及当我输入cat runtime.txt时,这显示在我上面发布的错误中。 I finally spotted this by using a Hex editor. 我终于通过使用Hex编辑器发现了这一点。 Therefore, Heroku was not only reading python-3.6.4 in my runtime.txt but also all this thing that I posted above before actually reading python-3.6.4. 因此,Heroku不仅在我的runtime.txt读取python-3.6.4 ,而且在实际阅读python-3.6.4.之前我在上面发布了所有这些内容python-3.6.4. and this is the reason why I was getting an error. 这就是我收到错误的原因。

As @Chris notes below at the comments, this unnecessary "text' was added (for some reason) because my .txt files were firstly saved (for some reason) as .txt.rtf and then I manually changed the extension to .txt without having in mind that something more was saved in them even thought I changed the extension. I deleted all this unnecessary "text" with my Hex editor and now everything is working fine. 正如@Chris在评论中注意到的那样,这个不必要的“文本”被添加(出于某种原因),因为我的.txt文件首先被保存(出于某种原因)为.txt.rtf然后我手动将扩展名更改为.txt而没有记住,即使我改变了扩展名,也保存了更多内容。我用Hex编辑器删除了所有这些不必要的“文本”,现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 推送被拒绝,无法编译Python应用,pythonnet:状态为“错误” - Push rejected, failed to compile Python app, pythonnet: finished with status 'error' 推送被拒绝,无法在 Heroku 上编译 Python 应用程序 - Push rejected, failed to compile Python app on Heroku 推送被拒绝,无法编译 Python 应用程序 - Push rejected, failed to compile Python app Heroku“推送被拒绝,无法编译Python应用” - Heroku “Push rejected, failed to compile Python app” Heroku推被拒绝,无法编译Python / django应用程序(Python 2.7) - Heroku push rejected, failed to compile Python/django app (Python 2.7) 推送被拒绝,无法在 heroku 中编译 Python 应用程序(Python 速成课程) - Push rejected, failed to compile Python app in heroku (Python Crash Course) Scrapy推送到Heroku会出现错误:推送被拒绝,无法编译Python应用 - Scrapy push to Heroku get error: Push rejected, failed to compile Python app 推送被拒绝,无法编译Python应用。 我无法将Django应用部署到Heroku - Push rejected, failed to compile Python app.| I can't deploy a Django app to Heroku 推送被拒绝,无法编译 python 项目 - Django,Heroku - Push rejected, failed to compile python project - Django , Heroku Heroku推送被拒绝-编译失败-Unicode错误 - Heroku push rejected - failed to compile - Unicode error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM