0

I have created my own image containing my project in an ubuntu system. I was able to successfully build the image. No error showed up build-time. However, at run-time, a python import error is thrown up. The package is "requests". I have tried running a separate install statement from Dockerfile. I have also tried just including it in requirements.txt. But both return the same error. What is the fix to this?

ModuleNotFoundError: No module named 'requests'

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" ]
Eswar
  • 1,201
  • 19
  • 45
  • 1
    It looks like you now have at least 2 versions of python in your container, the system one and the one you installed from deadsnakes. Your entrypoint might be pointing at the wrong python version (eg, the system python with `ubuntu:latest` which I think is Python 3.6, try updating your entrypoint to `"python3.7"`. You will also need to update your `RUN pip` line to use the correct python. – James Meakin Feb 18 '20 at 10:45
  • This worked. I found python 3.6.9 as well. Entrypoint python3 pointed to python 3.6.9 and not python3.7. Thanks. You can write it as the answer. – Eswar Feb 18 '20 at 11:03

0 Answers0