Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

python - Installing numpy on Docker Alpine

I'm trying to install numpy in a docker container based on Alpine 3.1. I'm using the following Dockerfile:

FROM alpine:3.1
RUN apk add --update make cmake gcc g++ gfortran
RUN apk add --update python py-pip python-dev
RUN pip install cython
RUN pip install numpy

This runs fine until pip install numpy when I get the following error:

error: Command "gcc -fno-strict-aliasing -Os -fomit-frame-pointer -DNDEBUG -Os -fomit-frame-pointer -fPIC -Inumpy/core/include -Ibuild/src.linux-x86_64-2.7/numpy/core/include/numpy -Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -I/usr/include/python2.7 -Ibuild/src.linux-x86_64-2.7/numpy/core/src/private -Ibuild/src.linux-x86_64-2.7/numpy/core/src/private -Ibuild/src.linux-x86_64-2.7/numpy/core/src/private -c build/src.linux-x86_64-2.7/numpy/core/src/npymath/ieee754.c -o build/temp.linux-x86_64-2.7/build/src.linux-x86_64-2.7/numpy/core/src/npymath/ieee754.o" failed with exit status 1

easy_install-2.7 numpy gives the same error.

Are there any config/installation steps I'm missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've been having a bit of trouble with this myself and, long story short, I would encourage you to ask if it's really worth the hassle. Numpy is enormous when you start adding things to the stack like pandas, gpus, and scipy so the benefit of building it on alpine is limited, the savings over using Debian, Arch, or even Ubuntu are relatively modest when 500MB of your space is on this library anyway.

That having been said, I threw together an image that does it. I needed as build-time dependencies musl-dev, linux-headers, and g++. I also wound up needing to add openblas from edge for something later in the stack so it's possible that some dependencies from that are required too. But I believe just adding the three former libraries with

apk --no-cache add musl-dev linux-headers g++

should be sufficient to prevent the gcc error you are getting. You can view the image at https://hub.docker.com/r/o76923/alpine-numpy-stack/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...