在Alpine Linux上安装sklearn时缺少numpy标头

问题描述 投票:1回答:1

我正在尝试在Docker映像(FROM astronomerinc/ap-airflow:master-1.10.5-onbuild)上安装sklearn。源图像附带的环境:

  • Alpine Linux v3.10(内核4.9.93-linuxkit-aufs
  • Python 3.7.3
  • numpy == 1.17.2
  • pandas == 0.25.1
  • 大熊猫-吉贝== 0.11.0
  • ...

我在scipy==1.3.1中有requirements.txt,并且没有通过pip安装它的问题,但是当我将scikit-learn添加到requirements.txt并再次重建时,出现此错误,提示缺少numpy标头:

    creating build/temp.linux-x86_64-3.7
    creating build/temp.linux-x86_64-3.7/sklearn
    creating build/temp.linux-x86_64-3.7/sklearn/svm
    creating build/temp.linux-x86_64-3.7/sklearn/svm/src
    creating build/temp.linux-x86_64-3.7/sklearn/svm/src/libsvm
    compile options: '-I/usr/lib/python3.7/site-packages/numpy/core/include -c'
    g++: sklearn/svm/src/libsvm/libsvm_template.cpp
    ar: adding 1 object files to build/temp.linux-x86_64-3.7/liblibsvm-skl.a
    running build_ext
    customize UnixCCompiler
    customize UnixCCompiler using build_ext
    resetting extension 'sklearn.svm.liblinear' language from 'c' to 'c++'.
    customize UnixCCompiler
    customize UnixCCompiler using build_ext
    building 'sklearn.__check_build._check_build' extension
    compiling C sources
    C compiler: gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -DTHREAD_STACK_SIZE=0x100000 -fPIC

    creating build/temp.linux-x86_64-3.7/sklearn/__check_build
    compile options: '-I/usr/lib/python3.7/site-packages/numpy/core/include -I/usr/lib/python3.7/site-packages/numpy/core/include -I/usr/include/python3.7m -c'
    gcc: sklearn/__check_build/_check_build.c
    gcc -shared -Wl,--as-needed -Wl,--as-needed build/temp.linux-x86_64-3.7/sklearn/__check_build/_check_build.o -L/usr/lib -Lbuild/temp.linux-x86_64-3.7 -lpython3.7m -o build/lib.linux-x86_64-3.7/sklearn/__check_build/_check_build.cpython-37m-x86_64-linux-gnu.so
    building 'sklearn.cluster._dbscan_inner' extension
    compiling C++ sources
    C compiler: g++ -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -DTHREAD_STACK_SIZE=0x100000 -fPIC

    creating build/temp.linux-x86_64-3.7/sklearn/cluster
    compile options: '-I/usr/lib/python3.7/site-packages/numpy/core/include -I/usr/lib/python3.7/site-packages/numpy/core/include -I/usr/include/python3.7m -c'
    g++: sklearn/cluster/_dbscan_inner.cpp
    sklearn/cluster/_dbscan_inner.cpp:652:10: fatal error: numpy/arrayobject.h: No such file or directory
     #include "numpy/arrayobject.h"
              ^~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    error: Command "g++ -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/lib/python3.7/site-packages/numpy/core/include -I/usr/lib/python3.7/site-packages/numpy/core/include -I/usr/include/python3.7m -c sklearn/cluster/_dbscan_inner.cpp -o build/temp.linux-x86_64-3.7/sklearn/cluster/_dbscan_inner.o -MMD -MF build/temp.linux-x86_64-3.7/sklearn/cluster/_dbscan_inner.o.d" failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-o8ktwf40/scikit-learn/setup.py'"'"'; __file__='"'"'/tmp/pip-install-o8ktwf40/scikit-learn/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-p6ejlhi_/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.
WARNING: You are using pip version 19.2.1, however version 19.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The command '/bin/sh -c pip install --no-cache-dir -q -r requirements.txt' returned a non-zero code: 1


我尝试过的几件事:

  • 升级点
  • 指定scikit-learn的较早版本
  • “”明确地“安装py3-numpy

不幸的是,他们都没有工作。 This post建议手动设置路径,但这并不是我要找的答案。

洞察?任何帮助表示赞赏!

python docker scikit-learn pip alpine
1个回答
0
投票

我建议您将py-numpy-dev安装在Dockerfile中:

 RUN apk add  py-numpy-dev
© www.soinside.com 2019 - 2024. All rights reserved.