所以我的 dockerfile 是:
FROM iron/python:2.7
WORKDIR /app
ADD . /app
RUN pip install --upgrade pip
RUN pip install -r ./requirements.txt
最近当我构建我的图像时:
docker build --no-cache -t <image name>:<tag>
我遇到以下问题:
Step 4/6 : RUN pip install --upgrade pip
---> Running in 00c781a53487
/bin/sh: pip: not found
The command '/bin/sh -c pip install --upgrade pip' returned a non-zero code: 127
docker 是否有任何更改可能导致此问题?因为上周这一切都很好,并且使用完全相同的代码构建图像没有问题。
对于 Python3:
FROM ubuntu:latest
WORKDIR /app
ADD . /app
RUN set -xe \
&& apt-get update \
&& apt-get install python3-pip
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
如果你也为 Python2 安装了
python-pip
,你需要为 Python3 使用 pip3
,为 Python2 使用 pip
。但是在这个设置下,pip
和 pip3
是一样的。检查pip -V
.
就是这样:-)
你必须先安装pip。
FROM iron/python:2.7
WORKDIR /app
ADD . /app
RUN set -xe \
&& apt-get update \
&& apt-get install python-pip
RUN pip install --upgrade pip
RUN pip install -r ./requirements.txt
添加到@vijayraj34 答案
确保为 ubuntu 添加自动是安装更新和 pip 而无需请求用户输入
像这样
RUN set -xe \
&& apt-get update -y \
&& apt-get install -y python3-pip
RUN set -xe && apt-get -yqq update && apt-get -yqq install python3-pip && pip3 install --upgrade pip
我用 pip3 工作过