【问题标题】:"ERROR: No matching distribution found for numpy" when deploying app to Heroku将应用程序部署到 Heroku 时出现“错误:找不到 numpy 的匹配分布”
【发布时间】:2021-02-13 07:46:24
【问题描述】:

我正在尝试将我的 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 中删除有问题的依赖项。但在这种情况下,我的程序需要它。

任何建议都将不胜感激,因为我已经碰壁了。

【问题讨论】:

  • 您是否为 Heroku 提供了 runtime.txt? Heroku 并不关心您在 local 环境中使用的 Python。它有自己的环境,如果你想让它使用特定的 Python 版本,你必须明确告诉它使用哪一个。见devcenter.heroku.com/articles/python-runtimes
  • 添加 runtime.txt 时出现以下错误。请求的运行时 (Python 3.8.2) 不适用于此堆栈 (heroku-20)。所以我需要将我的 Python 版本更改为可接受的堆栈?

标签: python-3.x numpy heroku


【解决方案1】:

从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's PyPi releases page1.20.1确实是一个有效的版本。但是,检查NumPy 1.20.0 release notes 有这个信息,

此版本支持的 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 runtime environment,它不知道也不关心你在本地环境中使用的 Python 版本。它将使用所选堆栈的默认 Python 版本(在您的情况下为“Heroku-20”),如果您希望它使用特定的 Python 版本,您必须明确告诉它要使用哪个版本使用。

来自其list of supported runtimes

默认情况下,新创建的 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 不兼容。

修复很简单:specify the runtime:

要指定 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 指定的内容。

【讨论】:

    【解决方案2】:

    在我的例子中,我们想要从一个要求*.txt 文件中安装 pip 模块,该文件中定义了 锁定 模块的版本并且仅从 内部 Artifactory 服务器解析(而不是在线,即 pypi.org

    例如:requirements.txt 文件

    numpy==1.16.2
    pandas==1.0.3
    ..
    ...
    

    要解决此问题:我必须使用 NO_PROXY=<value> 作为环境变量。

    假设您的工件服务器是:my-artifactory.company.local 或 my-artifactory.company.com,那么我们只需要确保NO_PROXY 变量的值中列出了该主机名的“domain”部分。

    即为了 my-artifactory.company.com 或 my-artifactory.company.local,value inside

    NO_PROXY 变​​量必须包含:,.company.com,.company.local,...

    示例导出的变量(在命令行 $ 提示符):

    export NO_PROXY=localhost,127.0.0.1,169.254.169.254,169.254.169.123,.somecompany.com,.company.com,.company.local,pki.company.com,s3-us-gov-west-1.amazonaws.com,s3-fips-us-gov-west-1.amazonaws.com,rds.amazonaws.com,10.201.12.244,10.201.44.62,10.201.32.261

    ====

    如果您使用的是Dockerfile,那么请确保您正确设置了 ARG/ENV 变量。 ARG 在构建时使用(可以在命令行中使用 --build-arg 发送到docker build -t tag . 的选项覆盖,它将在当前目录中搜索 Dockerfile 并创建映像。ENV 在运行时使用(docker run ) 并且也可以被覆盖。

    示例 Dockerfile 是:

    FROM python:3.7
    
    MAINTAINER giga.sangal@company.com
    
    ARG PYTHONBUFFERED=0
    ARG HTTPS_PROXY=http://proxy.ext.company.com:80
    ARG HTTP_PROXY=http://proxy.ext.company.com:80
    ARG NO_PROXY=localhost,127.0.0.1,169.254.169.254,.company.com,.company.local,pki.company.com,s3-us-gov-west-1.amazonaws.com,s3-fips-us-gov-west-1.amazonaws.com,rds.amazonaws.com
    
    ENV PYTHONBUFFERED=${PYTHONBUFFERED}
    ENV HTTPS_PROXY=${HTTPS_PROXY}
    ENV HTTP_PROXY=${HTTP_PROXY}
    ENV NO_PROXY=${NO_PROXY}
    
    # If there are 3 requirements files in source control, I'm copy all for pip install, you don't have to. Use what modules you want / file you want.    
    RUN mkdir -p code
    COPY requirements.txt /code
    COPY requirements-test.txt /code
    COPY requirements-dev.txt /code
    
    WORKDIR /code
    
    # You can fetch from pypi.org but in my case, this was a security issue.
    # RUN pip install --trusted-host pypi.org -r requirements.txt
    
    RUN pip install --no-cache-dir --trusted-host my-artifactory.company.local -r requirements.txt -r requirements-test.txt -r requirements-dev.txt --index-url http://my-artifactory.company.local:8081/artifactory/api/pypi/pypi-local-deps/simple --disable-pip-version-check
    

    在我的案例中解决问题的主线是使用 NO_PROXY(如上所列)。

    任何与 pip 模块相关的问题,或未找到模块版本,或任何 SSL 错误SSLError(SSLCertVerificationError 类似错误,在 cmd 行 应用上述 NO_PROXY 后消失Dockerfile

    WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1091)'))': /simple/requests/
    

    ERROR: Could not find a version that satisfies the requirement requests
    ERROR: No matching distribution found for requests
    

    ERROR: Could not find a version that satisfies the requirement numpy==1.16.2
    ERROR: No matching distribution found for numpy==1.16.2
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-15
      • 2022-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-17
      • 1970-01-01
      相关资源
      最近更新 更多