无法在树莓派中的 docker python3.7-slim 上安装 numpy

gui*_*cha 3 python numpy raspberry-pi docker

我正在尝试通过 docker 在新的 Raspberry pi 4 b 中部署一个小型微服务。该服务目前在我的 Windows 电脑上运行得很好,我什至可以在本地运行该服务到 pi 中。到目前为止,我已经能够在创建 docker 映像时追踪到 numpy 安装的错误。

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
Run Code Online (Sandbox Code Playgroud)

我相信稍后会显示重要的信息,它告诉我我无法编译某些 numpy 的库。

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
Run Code Online (Sandbox Code Playgroud)

如何复制: Dockerfile:

FROM python:3.7-slim
WORKDIR /usr/src/app
COPY . .

RUN apt-get update \
    && pip install -r requirements.txt 

Run Code Online (Sandbox Code Playgroud)

要求.txt:

numpy==1.19.1
Run Code Online (Sandbox Code Playgroud)

类似的帖子通过向 Dockerfile 添加更多指令显示了一些进展,但我没有看到任何改进

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 
Run Code Online (Sandbox Code Playgroud)

ndc*_*clt 5

slim 镜像没有编译 numpy 的工具。您必须在尝试安装 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/*

Run Code Online (Sandbox Code Playgroud)

清洁建筑工具后的线条pip install -r requirements.txt

它应该工作得更好。

另一种解决方案是使用python:3.7图像而不是python:3.7-slim.

编辑
有关 aarch64 上 numpy 的一些链接:

  • conda repo 上支持 aarch64 的问题,
  • miniforge在 x86_64 以外的其他架构上使用 conda 构建软件包。

编辑
OP在评论中给出的工作解决方案:

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
Run Code Online (Sandbox Code Playgroud)