30

So my dockerfile is :

FROM iron/python:2.7

WORKDIR /app
ADD . /app

RUN pip install --upgrade pip
RUN pip install -r ./requirements.txt

Recently though when I build my image with: docker build --no-cache -t <image name>:<tag>

I run into the issue of:

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

was there any changes to docker that might have caused this? Because last week this was all fine and there were no issues building the image with the same exact code.

Raphael Baysa
  • 301
  • 1
  • 3
  • 3

4 Answers4

21

For 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

If you install python-pip for Python2 as well, you need to use pip3 for Python3 and pip for Python2. But with this setting, pip is the same as pip3. Check with pip -V.

Thats it :-)

questionto42
  • 7,175
  • 4
  • 57
  • 90
vijayraj34
  • 2,135
  • 26
  • 27
13

You have to install pip first.

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
vanhonit
  • 607
  • 1
  • 5
  • 14
  • 3
    adding that line of code give: Step 4/7 : RUN set -xe && apt-get update && apt-get install python- pip ---> Running in 0cca59ad3d01 + apt-get update /bin/sh: apt-get: not found. Seems like commands like apt-get that should be there aren't found at all when the image is being created. – Raphael Baysa Feb 02 '18 at 18:33
  • I have checked the image iron/python:2.7. That not use debian base. You can try change to use FROM python:2.7-slim instead of FROM iron/python:2.7 – vanhonit Feb 02 '18 at 18:38
  • Package 'python-pip' has no installation candidate – imranjust14 Aug 21 '22 at 07:04
12

Adding to @vijayraj34 answer

Ensure you add an auto yes for ubuntu to install the updates and pip without requesting user input

Like so

RUN set -xe \
    && apt-get update -y \
    && apt-get install -y python3-pip
1

RUN set -xe && apt-get -yqq update && apt-get -yqq install python3-pip && pip3 install --upgrade pip

for me worked with pip3

Opacho And
  • 35
  • 5
  • Please format any bash commands using code formatting "backticks" (like `this`). This will make it easier for potential readers to copy and paste your suggested command. – Donna Mar 25 '23 at 13:49