Is sklearn compatible with Linux-alpine?
Asked Answered
F

2

9

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
Ferrari answered 14/6, 2019 at 1:39 Comment(3)
did you solve this?Peltate
Not yet. For the moment, I'm just sticking with a non-alpine image. :-(Ferrari
That's what I ended up doingPeltate
M
2

UPDATE: Since 2020 there is an official sklearn alpine package, which can easily be installed via:

apk add py3-scikit-learn

https://pkgs.alpinelinux.org/package/edge/community/x86/py3-scikit-learn

I would even recommend this way, instead of using pip. Some people (including me) encountered problems while trying the pip-way for scipy and/or sklearn:

Scipy error in python:3.8-alpine3.11 - No lapack/blas resources found

Moralist answered 5/5, 2023 at 16:49 Comment(0)
H
2

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 .
Hallucination answered 20/11, 2019 at 7:31 Comment(0)
M
2

UPDATE: Since 2020 there is an official sklearn alpine package, which can easily be installed via:

apk add py3-scikit-learn

https://pkgs.alpinelinux.org/package/edge/community/x86/py3-scikit-learn

I would even recommend this way, instead of using pip. Some people (including me) encountered problems while trying the pip-way for scipy and/or sklearn:

Scipy error in python:3.8-alpine3.11 - No lapack/blas resources found

Moralist answered 5/5, 2023 at 16:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.