首页 > 解决方案 > Docker build ERROR: 找不到满足要求的版本torch==1.5.1

问题描述

我有一个具有以下格式的 Dockerfile:

FROM python:latest
ADD requirements.txt .
RUN pip3 install -r requirements.txt
CMD ["python", "script.py"]

我的 requirements.txt 看起来像:

grpcio==1.31.0
grpcio-tools==1.31.0
torch==1.5.1

当我执行时,docker image build .我收到以下错误:

Sending build context to Docker daemon  61.44kB
Step 1/7 : FROM python:latest
 ---> dfc47c6cee13
Step 2/7 : ADD requirements.txt .
 ---> Using cache
 ---> 3be914d5b849
Step 3/7 : RUN pip3 install -r requirements.txt
 ---> Running in 372c329c76fa
Collecting grpcio==1.31.0
  Downloading grpcio-1.31.0.tar.gz (20.0 MB)
Collecting grpcio-tools==1.31.0
  Downloading grpcio-tools-1.31.0.tar.gz (2.1 MB)
ERROR: Could not find a version that satisfies the requirement torch==1.5.1 (from -r requirements.txt (line 3)) (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2)
ERROR: No matching distribution found for torch==1.5.1 (from -r requirements.txt (line 3))
The command '/bin/sh -c pip3 install -r requirements.txt' returned a non-zero code: 1

这是一个奇怪的错误,因为如果我没记错的话,torch 能够在最近(早在 2 周前)安装,所以我不确定为什么会发生这种情况。

标签: dockerdockerfilepytorchtorchtorchvision

解决方案


我通过更改 Dockerfile 中的版本而不是这样做来解决这个问题

FROM python:latest

将其更改为

FROM python:3.7.4

我认为torch 在安装python3.9.0 时存在问题,这就是python:latest 几天前更新的内容。最好强制 docker 容器使用特定的已知版本:)


推荐阅读