One - One Code All

Blog Content

alpine基础镜像安装python数据科学计算包

Python Linux-Mac 容器化   2019-03-15 11:51:03

alpine基础镜像安装python数据科学计算包


构建镜像

基础镜像使用justgast/python36-alpine38-bot

如果需要安装bash,可以使用下面的Dockerfile:

FROM justgast/python36-alpine38-bot

MAINTAINER Rethink

RUN echo "http://mirrors.aliyun.com/alpine/v3.8/main/" > /etc/apk/repositories
RUN echo "http://mirrors.aliyun.com/alpine/v3.8/community/" >> /etc/apk/repositories
RUN echo "http://dl-2.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories;
RUN echo "http://dl-3.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories;
RUN echo "http://dl-4.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories;
RUN echo "http://dl-5.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories

RUN echo "ipv6" >> /etc/modules
RUN apk update \
        && apk upgrade \
        && apk add --no-cache bash \
        bash-doc \
        bash-completion \
        && rm -rf /var/cache/apk/* \
        && /bin/bash


执行下面的命令构建镜像:

docker build -t alpine-bash:v1 .


进入镜像:

docker run -dti -v ~/share_file/:/share_file alpine-bash:v1


安装数据科学相关依赖

如果要安装Numpy、Scipy、Matlotlib、Scikit-Learn、Pandas等包,则需要额外安装gcc依赖


参考:https://stackoverflow.com/questions/52712447/alpine-linux-cant-install-lapack-dev-on-python3-5-alpine3-4

参考:

https://stackoverflow.com/questions/38568476/installing-seaborn-on-docker-alpine
RUN apk add gcc freetype-dev 
RUN apk add gfortran musl-dev g++ libgcc libquadmath musl libgfortran 
RUN apk add lapack-dev


报错异常解决

问题1

ModuleNotFoundError: No module named 'Cython'


解决方法如下:

pip install cython


问题2

如果是离线安装包,则有可能报以下错误:

ERROR: Could not find a version that satisfies the requirement scikit-learn==0.20.3 (from -r requirements.txt (line 30)) (from versions: none)

ERROR: No matching distribution found for scikit-learn==0.20.3 (from -r requirements.txt (line 30))


解决方法如下:

pip download scikit-learn==0.20.3


问题3

EnvironmentError: mysql_config not found

解决方法如下:

RUN apk add --no-cache mariadb-dev build-base


参考:https://github.com/gliderlabs/docker-alpine/issues/181


问题4

安装pymssql的时候报错:


     #include "sqlfront.h"

                          ^

    compilation terminated.

    error: command 'gcc' failed with exit status 1


解决办法如下:

apk add freetds-dev


问题5

安装uwsgi的时候报错:

    *** uWSGI compiling server core ***

    [gcc] core/utils.o

    In file included from core/utils.c:1:0:

    ./uwsgi.h:238:26: fatal error: linux/limits.h: No such file or directory

     #include

                              ^

    compilation terminated.


解决办法如下:

apk add linux-headers



上一篇:Linux nohup实现后台运行程序及查看(nohup与&)
下一篇:docker(基于Alpine) 内安装numpy, matloplib, pillow安装依赖

The minute you think of giving up, think of the reason why you held on so long.