首页 > 解决方案 > 将 python 烧瓶应用程序上传到 Heroku 会引发错误

问题描述

在将我的 python 烧瓶应用程序上传到 Heroku 时,出现以下错误:

ERROR: Could not find a version that satisfies the requirement dataclasses==0.8 (from -r /tmp/build_d980c139/requirements.txt (line 4)) (from versions: 0.1, 0.2, 0.3, 0.4, 0.5, 0.6)
remote:        ERROR: No matching distribution found for dataclasses==0.8 (from -r /tmp/build_d980c139/requirements.txt (line 4))
remote:  !     Push rejected, failed to compile Python app.

标签: pythonamazon-web-servicesflaskheroku

解决方案


Heroku 为您的应用程序安装最新的 python 版本。目前我假设它正在安装 python 版本 3.9.6。但是从 python 3.8.0 起,dataclasses==0.8 是在那里预先构建的。此外部数据类库仅存在于 0.1 - 0.6 版本(显示在错误消息中),并且可能已停止升级,因为它现在在预构建中退出。由于它没有找到那个特定的 0.8 版本,所以它抛出了那个未找到的错误。

现在要解决这个问题,有两种方法 - 简单的方法是从 requirements.txt 中删除 dataclasses==0.8 并上传。

另一种方法是将 dataclasses==0.8 保留在 requirements.txt 中,并在您的 requirements.txt 所在的同一根目录中添加另一个名为“runtime.txt”的 txt 文件。而这条线 - Python {yourspecifiedversion}。这将告诉 Heroku 要安装哪个 python 版本。您可以选择与所有外部库正确匹配的 python 版本。但如果 python 版本低于 3.8.0,则需要添加 'dataclasses==0.8'

在此链接中指定 Heroku 上的 python 运行时 -指定 Python 运行时


推荐阅读