0

我在 ubuntu 系统中创建了包含我的项目的自己的图像。我能够成功构建图像。没有错误显示构建时间。但是,在运行时,会抛出 python 导入错误。包是“请求”。我尝试从 Dockerfile 运行单独的安装语句。我也尝试将其包含在 requirements.txt 中。但两者都返回相同的错误。有什么办法解决这个问题?

ModuleNotFoundError:没有名为“请求”的模块

Dockerfile:

FROM ubuntu:latest

RUN apt-get update && apt-get install -y software-properties-common
RUN add-apt-repository -y ppa:deadsnakes/ppa
RUN apt-get update && apt-get install -y python3.7
RUN apt-get install -y python3.7 curl python3-distutils && curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python3.7 get-pip.py
RUN apt-get install -y build-essential libssl-dev libffi-dev python3.7-dev
RUN pip3 install requests
RUN rm -rf /var/lib/apt/lists/*

# We copy just the requirements.txt first to leverage Docker cache
COPY ./requirements.txt /dummy/requirements.txt

WORKDIR /dummy

RUN pip install -r requirements.txt

COPY . /dummy

ENTRYPOINT [ "python3" ]

CMD [ "main.py" ]
4

0 回答 0