[英]Push rejected, failed to compile Python app, pythonnet: finished with status 'error'
[英]Push rejected, failed to compile Python app - Python version error
我過去使用過Heroku和PHP,但這是我第一次使用Heroku和Python和Flask。 首先,我想創建一個簡單的“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)
一個帶有index.html
文件的templates
文件(見上文)
一個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),但我得到了同樣的錯誤。
首先,我將弄清楚如何使用gunicorn運行您的應用程序,因為這是Flask應用程序最常用的部署服務器。 要使用gunicorn運行您的應用程序,您應該能夠pip install gunicorn
,然后從項目的根目錄運行: gunicorn my_file_name:app
,其中my_file_name ==包含上面Flask代碼的文件的名稱。 例如,如果您的Flask代碼位於名為app.py的文件中,那么您將運行gunicorn app:app
。
一旦你可以使用gunicorn運行應用程序,創建一個Procfile,指定你希望Heroku運行帶有gunicorn的服務器。 這是Procfile
的內容,它應該位於項目文件的根目錄中(與requirements.txt
相同的目錄):
web: gunicorn app:app
然后我會更新requirements.txt
。 做pip freeze | grep gunicorn
pip freeze | grep gunicorn
獲取你的gunicorn版本,然后將其添加到requirements.txt
文件:
Flask==1.0.1
gunicorn==19.7.1
最后,為了解決上述錯誤的直接原因,我將runtime.txt
設置為:
python-3.6.4
那么git push heroku master
應該可以讓你去...
如果所有其他方法都失敗了, 這里有一個簡單的存儲庫 ,它在README中有一個帶有Heroku部署指令的准系統Flask應用程序。 它部署在這里: https : //myapp-name-1.herokuapp.com/
所以我發現它出了什么問題,現在我的“Hello World”可以在Heroku上正常運行。
問題是,即使我重新創建了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
當我在我的應用程序中嘗試執行git push heroku master
時以及當我輸入cat runtime.txt
時,這顯示在我上面發布的錯誤中。 我終於通過使用Hex編輯器發現了這一點。 因此,Heroku不僅在我的runtime.txt
讀取python-3.6.4
,而且在實際閱讀python-3.6.4.
之前我在上面發布了所有這些內容python-3.6.4.
這就是我收到錯誤的原因。
正如@Chris在評論中注意到的那樣,這個不必要的“文本”被添加(出於某種原因),因為我的.txt
文件首先被保存(出於某種原因)為.txt.rtf
然后我手動將擴展名更改為.txt
而沒有記住,即使我改變了擴展名,也保存了更多內容。我用Hex編輯器刪除了所有這些不必要的“文本”,現在一切正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.