python-3.x - 将应用程序部署到 Heroku 时出现“错误:找不到 numpy 的匹配分布”
问题描述
我正在尝试将我的 Dash 应用程序上传到 Heroku。我一直在关注文档,但是,当我去推送时,我收到以下错误:
ERROR: Could not find a version that satisfies the requirement numpy==1.20.1
remote: ERROR: No matching distribution found for numpy==1.20.1 (from -r / t tmp/build_32b7cf97/requirements.txt (line 19))
remote: ! Push rejected, failed to compile Python app.
我的 Python 版本是 3.8,pip 是 21.0.1。奇怪的是,我也在输出日志中看到了这一点:
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Python app detected
remote: -----> Installing python-3.6.12
remote: -----> Installing pip 20.1.1, setuptools 47.1.1 and wheel 0.34.2
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
Heroku 安装了 python 3.6 和 pip 20.1.1。这可能与问题有关吗?我已经寻找其他用户的类似问题,他们建议从 requirements.txt 中删除有问题的依赖项。但在这种情况下,我的程序需要它。
任何建议将不胜感激,因为我已经碰壁了。
解决方案
从 NumPy 安装错误开始:
remote: ERROR: Could not find a version that satisfies the requirement numpy==1.20.1 remote: ERROR: No matching distribution found for numpy==1.20.1 (from -r /tmp/build_32b7cf97/requirements.txt (line 19)) remote: ! Push rejected, failed to compile Python app.
这通常意味着 NumPy 版本不存在,或者您使用的 Python 版本不受该 NumPy 版本的支持。检查NumPy 的 PyPi 发布页面,1.20.1确实是一个有效版本。但是,检查NumPy 1.20.0 发行说明有此信息,
此版本支持的 Python 版本为 3.7-3.9,已放弃对 Python 3.6 的支持。
所以你的猜测是正确的,它与 Python 版本有关。
我的python版本是3.8,pip是21.0.1
...
Heroku安装了python 3.6和pip 20.1.1
Heroku 有自己的 Python 运行时环境,它不知道也不关心你在本地 env上使用的 Python 版本。它将使用所选堆栈的默认 Python 版本(在您的情况下为“Heroku-20”),如果您希望它使用特定的 Python 版本,您必须明确告诉它要使用哪个版本。
从其支持的运行时列表中:
默认情况下,新创建的 Python 应用程序使用 python-3.6.13 运行时。您还可以指定不同的受支持的 Python 版本。
支持的运行时
python-3.9.2
在所有支持的堆栈上python-3.8.8
在所有支持的堆栈上python-3.7.10
在所有支持的堆栈上python-3.6.13
在所有支持的堆栈上python-2.7.18
仅在 Heroku-16 和 Heroku-18 上
如果您没有告诉它使用 Python 3.8,那么它将使用您的 Heroku 堆栈的默认版本,目前是 Python 3.6.x。如上所述,3.6 与 NumPy 1.20.1 不兼容。
修复很简单:指定运行时:
要指定 Python 运行时,请将
runtime.txt
文件添加到应用程序的根目录,该文件声明要使用的确切版本号:$ cat runtime.txt python-3.9.0
因此,您需要添加一个runtime.txt
文件,并将一个版本放入受支持的运行时列表中(请参阅上面的链接),并且您的 numpy 版本支持:
python-3.8.8
最后,保持本地环境的Python 版本与部署环境的 Python 版本一致是一个很好的做法。基本上,确保更新您的 3.8.2 以匹配您在 runtime.txt 中为 Heroku 指定的内容。
推荐阅读
- python - 简化 mongodb pymongo 查询
- npm - 为什么 `npm pack` 从我的库中删除文件?
- google-analytics - Google Analytics 4:如何获取全局对象的名称(gtag)
- google-cloud-platform - 如何锁定到公共和私有部分的路由,这在 GCP 负载均衡器后面
- tinymce - 如何更改 tinyMCE 编辑器值以仅返回 html 元素
- azure-devops - 如何在其中一台匹配的服务器中运行部署组作业?
- c# - 通过 TableAdapters 使用 MySQL 链接数据集时导致并发冲突的原因是什么?
- string - Kotlin - 如何从多行字符串中修剪所有前导空格?
- envoyproxy - 如何在 Envoy 中使用速率限制描述符进行本地速率限制?
- javascript - 更新数据更改的 UI