Reputation: 78
I'm trying to deploy a small microservice in a new Raspberry pi 4 b over docker. This service is currently working just fine on my windows pc and I'm even able to locally run the service into the pi. So far I've been able to trace down the error to the numpy installation when creating a docker image.
Collecting numpy==1.19.1
Downloading numpy-1.19.1.zip (7.3 MB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Preparing wheel metadata: started
Preparing wheel metadata: still running...
Preparing wheel metadata: finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python /usr/local/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmpts0hfzam
cwd: /tmp/pip-install-ozdo_kbb/numpy
Complete output (226 lines):
Processing numpy/random/_bounded_integers.pxd.in
Processing numpy/random/_sfc64.pyx
Processing numpy/random/_philox.pyx
Processing numpy/random/_generator.pyx
Processing numpy/random/_mt19937.pyx
Processing numpy/random/_bounded_integers.pyx.in
Processing numpy/random/_pcg64.pyx
Processing numpy/random/mtrand.pyx
Processing numpy/random/bit_generator.pyx
Processing numpy/random/_common.pyx
I believe that the important piece of information is shown later and which tells me that I'm not able to compile some of the numpy's libraries.
creating build/src.linux-armv7l-3.7/numpy/distutils
building library "npymath" sources
Could not locate executable gfortran
Could not locate executable f95
Could not locate executable ifort
Could not locate executable ifc
Could not locate executable lf95
Could not locate executable pgfortran
Could not locate executable f90
Could not locate executable f77
Could not locate executable fort
Could not locate executable efort
Could not locate executable efc
Could not locate executable g77
Could not locate executable g95
Could not locate executable pathf95
Could not locate executable nagfor
don't know how to compile Fortran code on platform 'posix'
Running from numpy source directory.
setup.py:470: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates
How to replicate: Dockerfile:
FROM python:3.7-slim
WORKDIR /usr/src/app
COPY . .
RUN apt-get update \
&& pip install -r requirements.txt
requirements.txt:
numpy==1.19.1
Similar posts have shown some progress by adding a couple of more instructions to the Dockerfile but I see no improvement
RUN apt-get update \
&& apt-get upgrade \
&& apt-get install libc-dev -y \
&& apt-get install libatlas-base-dev -y \
&& pip install --pre numpy \
&& pip install -r requirements.txt
Upvotes: 3
Views: 5373
Reputation: 3108
The slim image doesn't have the tools for compiling numpy. You have to install them before trying installing numpy.
FROM python:3.7-slim
WORKDIR /usr/src/app
COPY . .
RUN apt-get update && \
apt-get install -y \
build-essential \
make \
gcc \
&& pip install -r requirements.txt \
&& apt-get remove -y --purge make gcc build-essential \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/*
Lines after the pip install -r requirements.txt
clean building tools.
It should work better.
Another solution is to use the python:3.7
image instead of python:3.7-slim
.
Edit
Some links about numpy on aarch64:
edit
a working solution given by the OP in comment:
FROM python:3.7-stretch
WORKDIR /usr/src/app COPY . .
RUN apt-get update \
&& apt-get install build-essential make gcc -y \
&& apt-get install dpkg-dev -y \
&& apt-get install libjpeg-dev -y \
&& pip install -r requirements.txt \
&& pip install --no-cache-dir . \
&& apt-get remove -y --purge make gcc build-essential \
&& apt-get auto-remove -y \
&& rm -rf /var/lib/apt/lists/* \
&& find /usr/local/lib/python3.7 -name "*.pyc" -type f -delete
Upvotes: 5