从Alpine Repository安装了python软件包,但在python中不可用

时间:2018-10-05 21:59:33

标签: python-2.7 docker alpine

我已经用Alpine linux构建了一个docker镜像。

在我的Dockerfile中,以下一行

RUN apk add --update py-numpy py-numpy-dev  py-scipy  py-numpy-f2py --repository http://dl-cdn.alpinelinux.org/alpine/v3.8/community

我看到一些与

相似的日志消息
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
(1/3) Installing py-numpy (1.14.3-r1)
(2/3) Installing openblas (0.3.0-r0)
(3/3) Installing py2-numpy (1.14.3-r1)
Executing busybox-1.28.4-r1.trigger
OK: 389 MiB in 104 packages

但是当我运行docker映像并放入python并运行

将numpy导入为np

我得到

ImportError: No module named numpy

此处是完整的终端会话

/app # python
Python 2.7.15 (default, Sep 12 2018, 02:38:23) 
[GCC 6.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named numpy
>>> 

所以我对为什么无法获取apk包感到有些困惑?

任何想法都会受到赞赏。

干杯, 泰勒

完整的Dockerfile。

注意:我也在Pandas和scipy上挣扎,所以正在网上查看其他docker文件,我敢肯定这可以清除一点。

FROM python:2.7-alpine3.8

RUN apk update && apk upgrade \
  && apk add ca-certificates \
  && rm -rf /var/cache/apk/*

RUN apk add --no-cache --virtual=build_dependencies make cmake gcc g++ git linux-headers libstdc++ && \
    apk del build_dependencies  && \
    apk add --no-cache libstdc++  && \
    rm -rf /var/cache/apk/*

#RUN apk add --update python-dev python py-pip py-setuptools
RUN apk add --no-cache --update musl musl-dev zlib libxml2 libxml2-dev libxml2-utils libxslt libxslt-dev py-httplib2 && \
    apk add --no-cache --update musl libffi libffi-dev libressl-dev gfortran libgfortran libstdc++ libgcc  cython cython-dev && \
    apk add --no-cache --update py-lxml py-jinja2 py-cffi py-cryptography py-netifaces py-mock py-markdown py-requests py-requests-oauthlib py-click && \
    rm -rf /var/cache/apk/*


#from the Community alpine repo
RUN apk add --no-cache --update py-numpy py-numpy-dev  py-scipy  py-numpy-f2py --repository http://dl-cdn.alpinelinux.org/alpine/v3.8/community && \
    rm -rf /var/cache/apk/*

ARG PANDAS_VERSION=0.23.4
RUN apk add --no-cache python-dev py-pip libstdc++ && \
    apk add --no-cache --virtual .build-deps g++ && \
    ln -s /usr/include/locale.h /usr/include/xlocale.h && \
    pip install pandas==${PANDAS_VERSION} && \
    apk del .build-deps


WORKDIR /app
ONBUILD ADD . /app

# Clean up APT when done
RUN  rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/apk/*

CMD ["/bin/ash"]

0 个答案:

没有答案