Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is sklearn compatible with Linux-alpine?

I get an error when I try to build an alpine based docker image that includes the sklearn package.

I've tried a few variations of pip installation, different package combinations, and outdated versions of sklearn to see if they are compatible. I've also run the container in -it mode and tried to install the package manually from there. When I remove the sklearn line, the Dockerfile builds and the container runs just fine. Sklearn works in an Ubuntu:latest Dockerfile I've built, but I'm trying to reduce my footprint, so I was hoping to get it to work on alpine...

Here's my Dockerfile code:

FROM alpine:latest
RUN apk upgrade --no-cache \
  && apk update \
  && apk add --no-cache \
    musl \
    build-base \
    python3 \
    python3-dev \
    postgresql-dev \
    bash \
    git \
  && pip3 install --no-cache-dir --upgrade pip \
  && pip3 install sklearn \
  && rm -rf /var/cache/* \
  && rm -rf /root/.cache/*

And here's the error I'm getting:

ERROR: Command "/usr/bin/python3.6 /usr/lib/python3.6/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmpqjsz0004" failed with error code 1 in /tmp/pip-install-xlvbli9u/scipy
like image 474
AreToo Avatar asked Jun 14 '19 01:06

AreToo


1 Answers

Alpine Linux doesn't support PEP 513. I found that something like this works:

RUN apk add --no-cache gcc g++ gfortran lapack-dev libffi-dev libressl-dev musl-dev && \
    mkdir scipy && cd scipy && \
    wget https://github.com/scipy/scipy/releases/download/v1.3.2/scipy-1.3.2.tar.gz && \
    tar -xvf scipy-1.3.2.tar.gz && \
    cd scipy-1.3.2 && \
    python3 -m pip --no-cache-dir install .
like image 103
Sushen Kumar Avatar answered Sep 20 '22 00:09

Sushen Kumar