tl;dr

Install build tool and create symbolic link for locale.

$ apk add --update curl gcc g++
$ ln -s /usr/include/locale.h /usr/include/xlocale.h

$ pip install numpy
# => success

happy python life 🙂


error messages

Before install g++, I got error below,

    /usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find Scrt1.o: No such file or directory
    /usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find crti.o: No such file or directory
    /usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lssp_nonshared
    /usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lc
    /usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find crtn.o: No such file or directory
    collect2: error: ld returned 1 exit status
    /usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find Scrt1.o: No such file or directory
    /usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find crti.o: No such file or directory
    /usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lssp_nonshared
    /usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lc
    /usr/lib/gcc/x86_64-alpine-linux-musl/5.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find crtn.o: No such file or directory
    collect2: error: ld returned 1 exit status

// ...


      File "numpy/core/setup.py", line 653, in get_mathlib_info
        raise RuntimeError("Broken toolchain: cannot link a simple C program")
    RuntimeError: Broken toolchain: cannot link a simple C program

And next, before create symbolic link to /usr/include/xlocale.h, I got error message below,

...

         if (base == -1) {
                  ^
   numpy/core/src/multiarray/datetime_strings.c: In function 'array_datetime_as_string':
    numpy/core/src/multiarray/datetime_strings.c:1415:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if (unit == -1) {
                          ^
    numpy/core/src/multiarray/datetime_strings.c:1422:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (unit != -1 && !can_cast_datetime64_units(meta->base, unit, casting)) {
                      ^
    gcc: numpy/core/src/multiarray/datetime_busdaycal.c
    gcc: numpy/core/src/multiarray/refcount.c
    numpy/core/src/multiarray/refcount.c: In function '_fillobject':
    numpy/core/src/multiarray/refcount.c:279:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (i = 0; i < dtype->elsize / sizeof(obj); i++) {
                           ^
    gcc: numpy/core/src/multiarray/numpyos.c
    numpy/core/src/multiarray/numpyos.c:18:21: fatal error: xlocale.h: No such file or directory
    compilation terminated.
    numpy/core/src/multiarray/numpyos.c:18:21: fatal error: xlocale.h: No such file or directory
    compilation terminated.

Dockerfile

I use official docker image for python.
This Dockerfile use it and install numpy and pandas.

FROM python:3.5-alpine

RUN apk add --update curl gcc g++ \
    && rm -rf /var/cache/apk/*

RUN ln -s /usr/include/locale.h /usr/include/xlocale.h

RUN pip install bottle numpy cython pandas

CMD tail -f /dev/null

2 thoughts on “Install numpy and pandas on alpine:python3

Leave a Reply

Your email address will not be published. Required fields are marked *