Home > Mobile >  What packages are required on Alpine to run numpy after build
What packages are required on Alpine to run numpy after build

Time:12-30

I am planning to build NumPy on Alpine Linux container. To do so I will first install the following packages.

apk add --no-cache --virtual build-dependencies musl-dev linux-headers g

My question is, does NumPy rely on these packages (i.e. musl-dev linux-headers g ) to run or is it just for the build, can I just delete them after build? ( i.e. apk del build-dependencies ) Likewise same question for pandas which needs more of these build dependencies.

CodePudding user response:

No.

Building numpy from source numpy-1.21.5.zip in alpine:

apk add python3 python3-dev cython py3-setuptools gcc gfortran g  
unzip numpy-1.21.5.zip
cd numpy-1.21.5
python3 setup.py build
python3 setup.py install

After this, the only runtime requirements are of course python and libc.musl-x86_64.so.1 which is part of musl. And it is a base package already required by python3.

~ # find /usr/lib/python3.9/site-packages/numpy-1.21.5-py3.9-linux-x86_64.egg/numpy/ -name "*.so" -print -exec sh -c 'readelf -d {} | grep NEEDED' \;
/usr/lib/python3.9/site-packages/numpy-1.21.5-py3.9-linux-x86_64.egg/numpy/core/_multiarray_tests.cpython-39-x86_64-linux-musl.so
 0x0000000000000001 (NEEDED)             Shared library: [libc.musl-x86_64.so.1]
/usr/lib/python3.9/site-packages/numpy-1.21.5-py3.9-linux-x86_64.egg/numpy/core/_multiarray_umath.cpython-39-x86_64-linux-musl.so
 0x0000000000000001 (NEEDED)             Shared library: [libc.musl-x86_64.so.1]
...

Edit: In order to make numpy faster, you need openblas (and openblas-dev at build time).

apk add openblas-dev

At runtime, numpy shared libraries will link to libopenblas.so.3 (part of openblas)

~ # readelf -d /usr/lib/python3.9/site-packages/numpy-1.21.5-py3.9-linux-x86_64.egg/numpy/core/_multiarray_umath.cpython-39-x86_64-linux-musl.so

Dynamic section at offset 0x40bb40 contains 20 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libopenblas.so.3]
 0x0000000000000001 (NEEDED)             Shared library: [libc.musl-x86_64.so.1]
...
  • Related