Why does it take ages to install Pandas on Alpine Linux

前端 未结 8 1390
孤独总比滥情好
孤独总比滥情好 2020-11-29 18:19

I\'ve noticed that installing Pandas and Numpy (it\'s dependency) in a Docker container using the base OS Alpine vs. CentOS or Debian takes much longer. I created a little t

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 18:57

    ANSWER: AS OF 3/9/2020, FOR PYTHON 3, IT STILL DOESN'T!

    Here is a complete working Dockerfile:

    FROM python:3.7-alpine
    RUN echo "@testing http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
    RUN apk add --update --no-cache py3-numpy py3-pandas@testing
    

    The build is very sensitive to the exact python and alpine version numbers - getting these wrong seems to provoke Max Levy's error so:libpython3.7m.so.1.0 (missing) - but the above does now work for me.

    My updated Dockerfile is available at https://gist.github.com/jtlz2/b0f4bc07ce2ff04bc193337f2327c13b


    [Earlier Update:]

    ANSWER: IT DOESN'T!

    In any Alpine Dockerfile you can simply do*

    RUN apk add py2-numpy@community py2-scipy@community py-pandas@edge
    

    This is because numpy, scipy and now pandas are all available prebuilt on alpine:

    https://pkgs.alpinelinux.org/packages?name=*numpy

    https://pkgs.alpinelinux.org/packages?name=*scipy&branch=edge

    https://pkgs.alpinelinux.org/packages?name=*pandas&branch=edge

    One way to avoid rebuilding every time, or using a Docker layer, is to use a prebuilt, native Alpine Linux/.apk package, e.g.

    https://github.com/sgerrand/alpine-pkg-py-pandas

    https://github.com/nbgallery/apks

    You can build these .apks once and use them wherever in your Dockerfile you like :)

    This also saves you having to bake everything else into the Docker image before the fact - i.e. the flexibility to pre-build any Docker image you like.

    PS I have put a Dockerfile stub at https://gist.github.com/jtlz2/b0f4bc07ce2ff04bc193337f2327c13b that shows roughly how to build the image. These include the important steps (*):

    RUN echo "@community http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
    RUN apk update
    RUN apk add --update --no-cache libgfortran
    

提交回复
热议问题