Installing seaborn on Docker Alpine

只愿长相守 提交于 2020-06-24 11:42:45

问题


I am trying to install seaborn with this Dockerfile:

FROM alpine:latest

RUN apk add --update python py-pip python-dev 

RUN pip install seaborn

CMD python

The error I get is related to numpy and scipy (required by seaborn). It starts with:

/tmp/easy_install-nvj61E/numpy-1.11.1/setup.py:327: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates

and ends with

File "numpy/core/setup.py", line 654, in get_mathlib_info

RuntimeError: Broken toolchain: cannot link a simple C program

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-DZ4cXr/scipy/

The command '/bin/sh -c pip install seaborn' returned a non-zero code: 1

Any idea how I can fix this?


回答1:


To fix this error, you need to install gcc: apk add gcc.

But you will see that you will hit a new error as numpy, matplotlip and scipy have several dependencies. You need to also install gfortran, musl-dev, freetype-dev, etc.

Here is a Dockerfile based on you initial one that will install those dependencies as well as seaborn:

FROM alpine:latest

# install dependencies
# the lapack package is only in the community repository
RUN echo "http://dl-4.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
RUN apk --update add --no-cache \ 
    lapack-dev \ 
    gcc \
    freetype-dev

RUN apk add python py-pip python-dev 

# Install dependencies
RUN apk add --no-cache --virtual .build-deps \
    gfortran \
    musl-dev \
    g++
RUN ln -s /usr/include/locale.h /usr/include/xlocale.h

RUN pip install seaborn

# removing dependencies
RUN apk del .build-deps

CMD python

You'll notice that I'm removing the dependencies using apk-del .build-deps to limit the size of your image (http://www.sandtable.com/reduce-docker-image-sizes-using-alpine/).

Personally I also had to install ca-certificates but it seems you didn't have this issue.

Note: You could also build your image FROM the python:2.7-alpine image to avoid installing python and pip yourself.



来源:https://stackoverflow.com/questions/38568476/installing-seaborn-on-docker-alpine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!