【问题标题】:Installing seaborn on Docker Alpine在 Docker Alpine 上安装 seaborn
【发布时间】:2016-11-28 20:07:15
【问题描述】:

我正在尝试使用此 Dockerfile 安装 seaborn

FROM alpine:latest

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

RUN pip install seaborn

CMD python

我得到的错误与numpyscipyseaborn 要求)有关。开头是:

/tmp/easy_install-nvj61E/numpy-1.11.1/setup.py:327:用户警告: 无法识别的 setuptools 命令,继续生成 Cython 来源和扩展模板

结尾

文件“numpy/core/setup.py”,第 654 行,在 get_mathlib_info 中

RuntimeError: Broken toolchain: cannot link a simple C program

命令“python setup.py egg_info”在/tmp/pip-build-DZ4cXr/scipy/中失败,错误代码为1

命令“/bin/sh -c pip install seaborn”返回非零代码:1

知道如何解决这个问题吗?

【问题讨论】:

    标签: numpy docker seaborn alpine


    【解决方案1】:

    要修复这个错误,你需要安装gcc:apk add gcc

    但是你会看到你会遇到一个新的错误,因为 numpy、matplotlip 和 scipy 有几个依赖项。还需要安装gfortranmusl-devfreetype-dev等。

    这是一个基于您的初始文件的 Dockerfile,它将安装这些依赖项以及 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
    

    您会注意到我正在使用 apk-del .build-deps 删除依赖项以限制您的图像大小 (http://www.sandtable.com/reduce-docker-image-sizes-using-alpine/)。

    就个人而言,我还必须安装 ca-certificates,但您似乎没有这个问题。

    注意:您还可以从python:2.7-alpine 映像构建您的映像,以避免自己安装 python 和 pip。

    【讨论】:

    • 太棒了,成功了。构建容器花费了很长时间,但最终它完成了(重量为 693.3 MB)。感谢您的出色回答(解决了我的问题,还教会了我一些关于 Docker 最佳实践的知识)。
    • @emh 不客气。我还必须构建包含 scipy 的图像,并且我确认它们需要很长时间才能从头开始构建。保持它们很小也很困难。至少它们比基于 Ubuntu 的图像小!
    • 我在测试存储库 ATM 中找不到lapack-dev(使用python:3.6-alpinepython:alpine docker 镜像别名),所以我需要使用dl-4.alpinelinux.org/alpine/latest-stable/community 来获取lapack-dev
    • @shadi 你说得对,包移到社区仓库,我会更新答案
    • 最近更新了numpy,编译失败。正如here 所写,您可以使用pip install numpy==1.14.3,但请注意,如果您也开始安装pandas,那么它将尝试再次引入最新版本的numpy
    猜你喜欢
    • 2016-01-30
    • 2016-06-11
    • 1970-01-01
    • 2020-11-29
    • 2018-07-13
    • 2019-07-20
    • 1970-01-01
    • 2020-10-17
    • 1970-01-01
    相关资源
    最近更新 更多