Python script with numpy in dockerfile on Raspberry PI – error

I want to run a Docker container on my Raspberry PI 2 with a Python script that uses numpy. For this I have the following Dockerfile:

FROM python:3.7
RUN pip install numpy

CMD ["python", ""]

But when I want to import numpy, I get the error message that was not found. I have also tried to install numpy with a wheel from, but the same error occurs.

The Google search revealed that I need to install the liblapack3. How do I need to modify my Dockerfile for this?

Inspired by the answer of om-ha, this worked for me:

FROM python:3.7
RUN apt-get update 
    && apt-get -y install libatlas-base-dev 
    && pip install numpy

CMD ["python", ""]


Working Dockerfile

# Python image (debian-based)
FROM python:3.7

# Create working directory

# Copy project files

# RUN command to update packages & install dependencies for the project
RUN apt-get update 
    && apt-get install -y 
    && pip install numpy

# Commands to run within the container
CMD ["python", ""]


  1. You have an extra trailing in your dockerfile, this is used for multi-line shell commands actually. You can see this used in-action here. I used this in my answer above. Beware the last shell command (in this case pip) does not need a trailing , a mishap that was done in the code you showed.
  2. You should probably use a working directory via WORKDIR /app
  3. Run apt-get update just to be sure everything is up-to-date.
  4. It’s recommended to group multiple shell commands within ONE RUN directive using &&. See best practices and this discussion.

Resources sorted by use in this dockerfile

  1. FROM
  3. COPY
  4. RUN
  5. CMD