Emma
Emma

Reputation: 449

Python script with numpy in dockerfile on Raspberry PI - libf77blas.so.3 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
COPY numpy_script.py /
RUN pip install numpy

CMD ["python", "numpy_script.py"]

But when I want to import numpy, I get the error message that libf77blas.so.3 was not found. I have also tried to install numpy with a wheel from www.piwheels.org, 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
COPY numpy_script.py /
RUN apt-get update \
    && apt-get -y install libatlas-base-dev \
    && pip install numpy

CMD ["python", "numpy_script.py"]

Upvotes: 2

Views: 688

Answers (1)

om-ha
om-ha

Reputation: 3572

Working Dockerfile

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

# Create working directory
WORKDIR /app

# Copy project files
COPY numpy_script.py numpy_script.py

# 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", "numpy_script.py"]

Explanation

  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 order of use in this dockerfile

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

Upvotes: 2

Related Questions