为什么我在部署到 heroku 时出错?

时间:2021-03-31 14:08:15

标签: flask heroku

我正在尝试将我的应用程序推送到 heroku,我正在遵循 udemy 的教程 - 一切都按照说明进行。一旦我到了最后一步 - 执行 git push heroku master 我在控制台中收到以下错误:

(flaskdeploy) C:\Users\dmitr\Desktop\jose\FLASK_heroku>git push heroku master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
remote:  !
remote:  !     git push heroku <branchname>:main
remote:  !
remote:  ! This article goes into details on the behavior:
remote:  !   https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: !       Push rejected to mitya-test-app.
remote:
To https://git.heroku.com/mitya-test-app.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/mitya-test-app.git'

在日志区域的 heroku 站点上,我对此错误有以下解释:

-----> Building on the Heroku-20 stack
-----> Determining which buildpack to use for this app
-----> Python app detected
-----> Installing python-3.6.13
-----> Installing pip 20.1.1, setuptools 47.1.1 and wheel 0.34.2
-----> Installing SQLite3
-----> Installing requirements with pip
       Collecting certifi==2020.12.5
         Downloading certifi-2020.12.5-py2.py3-none-any.whl (147 kB)
       Processing /home/linux1/recipes/ci/click_1610990599742/work
       ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/home/linux1/recipes/ci/click_1610990599742/work'
       
 !     Push rejected, failed to compile Python app.
 !     Push failed

在我的 requirements.txt 中,我有以下内容:

certifi==2020.12.5
click @ file:///home/linux1/recipes/ci/click_1610990599742/work
Flask @ file:///home/ktietz/src/ci/flask_1611932660458/work
gunicorn==20.0.4
itsdangerous @ file:///home/ktietz/src/ci/itsdangerous_1611932585308/work
Jinja2 @ file:///tmp/build/80754af9/jinja2_1612213139570/work
MarkupSafe @ file:///C:/ci/markupsafe_1607027406824/work
Werkzeug @ file:///home/ktietz/src/ci/werkzeug_1611932622770/work
wincertstore==0.2

事实上,这只是一个由app.py组成的超级简单的测试应用:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return "THE SITE IS OK"    

if __name__ == '__main__':
    app.run()

Procfile 里面有这个:

web: gunicorn app:app

2 个答案:

答案 0 :(得分:1)

我认为问题出在requirement.txt

删除

click @ file:///home/linux1/recipes/ci/click_1610990599742/work
Flask @ file:///home/ktietz/src/ci/flask_1611932660458/work
itsdangerous @ file:///home/ktietz/src/ci/itsdangerous_1611932585308/work
Jinja2 @ file:///tmp/build/80754af9/jinja2_1612213139570/work
MarkupSafe @ file:///C:/ci/markupsafe_1607027406824/work
Werkzeug @ file:///home/ktietz/src/ci/werkzeug_1611932622770/work

并替换为

Flask==1.1.2

因为heroku没有找到这些包。 heroku 将从 pypi 的 requiremts.txt 中提取包

答案 1 :(得分:1)

我在您的 requirements.txt 中看到了一个 Windows 路径。不确定您要在那里做什么,但您是否有任何理由从本地源安装软件包?

所以,我相信查看来自

的日志

ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/home/linux1/recipes/ci/click_1610990599742/work

表示 pip 尝试从不存在的目录安装。您的 heroku dyno(容器)尝试获取必要的依赖项,但在构建时失败。如果你不熟悉容器,本质上它是一个独立的准系统,将从头开始构建,因此需要安装它们(点击、烧瓶等)

tl;dr heroku 想从本地安装,失败。尝试更改 requirements.txt 例如

certifi==2020.12.5
click
Flask
gunicorn==20.0.4
itsdangerous
Jinja2
MarkupSafe
Werkzeug
wincertstore==0.2

强制 pip 从外部源(即 pypi)安装。