无法打开需求文件:[Errno 2] 没有这样的文件或目录:'requirements.txt'

10
我正在尝试在我的Ubuntu 18.04机器上构建一个Docker镜像,并在同一构建目录中找到了requirements.txt文件,但仍然出现以下错误:
“无法打开需求文件:[Errno 2]没有这样的文件或目录:'requirements.txt' 命令'/bin/sh -c pip3 install -r requirements.txt'返回非零代码:1”
requirements.txt用于使用pip3安装Python模块。
requirement.txt内容如下:
numpy opencv-contrib-python opencv-python scikit-image pillow imutils scikit-learn matplotlib progressbar2 beautifulsoup4 pandas matplotlib re2 regex json argparse pickle DockerFile:
FROM nvidia/cuda:10.1-cudnn7-runtime-ubuntu18.04

COPY requirements.txt /home/usr/app/requirements.txt
WORKDIR /home/usr/app/

RUN apt-get update && apt-get install -y python3 python3-pip sudo
RUN pip3 install -r requirements.txt

FROM tensorflow/tensorflow:latest-gpu-jupyter

请提供一个完整的Docker文件。 - stilManiac
1个回答

32

我怀疑你没有将 requirements.txt 文件复制到你的 Docker 镜像中。

通常,你需要在 Dockerfile 中添加以下行来复制你的 requirements.txt 文件并使用 pip 安装它:

COPY requirements.txt /tmp/requirements.txt
RUN python3 -m pip install -r /tmp/requirements.txt

如果你没有显式地将任何内容复制到Docker镜像中,那么除了基础镜像上的内容之外,你的镜像将没有任何数据。


谢谢,它起作用了。但是现在我面临新问题: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-9s4fxvhr/opencv-python/ The command '/bin/sh -c pip3 install -r requirements.txt' returned a non-zero code: 1 我对Docker还不熟悉,无法弄清楚如何解决这个问题。 - offset-null1
如果您能修改原始问题,包括Dockerfile和requirements.txt文件,我们可以更好地查看发生了什么。 - Michael Anckaert
完成。我不太确定是否可以使用两个基础图像。我想合并两个图像以在单个容器中使用。 - offset-null1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接