Python: apk add numpy is not working on python:2.7.11-alpine

Created on 31 May 2016  路  9Comments  路  Source: docker-library/python

Step to reproduce the problem:

FROM python:2.7.11-alpine

RUN echo @testing http://dl-cdn.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories && \
    apk add --update gfortran build-base py-numpy@testing

leads to:

Python 2.7.11 (default, May 12 2016, 18:32:26)
[GCC 5.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named numpy

Manually installing python from apk on clean Alpine docker image is working fine.

Issue

Most helpful comment

A really, really hacky workaround is to do something like ln -s locale.h /usr/include/xlocale.h, which allows me to successfully install numpy:

/ # ln -s locale.h /usr/include/xlocale.h
/ # pip install numpy
Collecting numpy
  Using cached numpy-1.11.1.zip
Building wheels for collected packages: numpy
  Running setup.py bdist_wheel for numpy ... done
  Stored in directory: /root/.cache/pip/wheels/10/1d/d8/608bdeaee5aad9e278259fa68d21a29c995a9117a250f7be26
Successfully built numpy
Installing collected packages: numpy
Successfully installed numpy-1.11.1

All 9 comments

The python in the alpine image is built from source directly and is not configured the same as the python from apk and would therefore know nothing about the py-numpy apk package. Also, it seems impossible to pip install numpy without applying their same patch: http://git.alpinelinux.org/cgit/aports/tree/testing/py-numpy/numpy-1.11.0-musl.patch. :cry:

This appears to be fixed:

$ docker run -it --rm python:2 sh
# pip install numpy
Collecting numpy
  Downloading numpy-1.11.1-cp27-cp27mu-manylinux1_x86_64.whl (15.3MB)
    100% |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 15.3MB 156kB/s 
Installing collected packages: numpy
Successfully installed numpy-1.11.1
# python
Python 2.7.12 (default, Aug  8 2016, 18:07:45) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> 

I'm a dummy; tested python:2 instead of python:2-alpine. :disappointed:

Yep, confirmed still an issue with upstream numpy:

$ docker run -it --rm python:2-alpine sh
/ # apk add --no-cache gcc musl-dev
...
/ # pip install numpy
...
  gcc: numpy/core/src/multiarray/number.c
  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.
  error: Command "gcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -Ibuild/src.linux-x86_64-2.7/numpy/core/src/private -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/local/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 numpy/core/src/multiarray/numpyos.c -o build/temp.linux-x86_64-2.7/numpy/core/src/multiarray/numpyos.o" failed with exit status 1

  ----------------------------------------
  Failed building wheel for numpy
...
    gcc: numpy/core/src/multiarray/number.c
    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.
    error: Command "gcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -Ibuild/src.linux-x86_64-2.7/numpy/core/src/private -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/local/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 numpy/core/src/multiarray/numpyos.c -o build/temp.linux-x86_64-2.7/numpy/core/src/multiarray/numpyos.o" failed with exit status 1

    ----------------------------------------
Command "/usr/local/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ctFB0g/numpy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ROVRNB-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-ctFB0g/numpy/

A really, really hacky workaround is to do something like ln -s locale.h /usr/include/xlocale.h, which allows me to successfully install numpy:

/ # ln -s locale.h /usr/include/xlocale.h
/ # pip install numpy
Collecting numpy
  Using cached numpy-1.11.1.zip
Building wheels for collected packages: numpy
  Running setup.py bdist_wheel for numpy ... done
  Stored in directory: /root/.cache/pip/wheels/10/1d/d8/608bdeaee5aad9e278259fa68d21a29c995a9117a250f7be26
Successfully built numpy
Installing collected packages: numpy
Successfully installed numpy-1.11.1

This is still not working.
docker run python:3-alpine /bin/sh -c "apk update && pip install --upgrade pip && pip install numpy"

EDIT: I got it working using posted comments and will shortly post a link to a dummy TensorFlow application used to test.

@tianon Perhaps the base image can include this line?

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

Or at least include something in the README saying that this is needed for installing numpy?

Although I guess this is technically backward incompatible because all Dockerfiles that have manually put this line will run into an error saying that the locale file already exists.

$ docker run -it --rm python:2-alpine sh
Unable to find image 'python:2-alpine' locally
2-alpine: Pulling from library/python
911c6d0c7995: Already exists 
17a85618b748: Pull complete 
3fc0dee7ce0d: Pull complete 
ed0218841895: Pull complete 
Digest: sha256:fbf776db54e0cf14a03ce7737c011c0f14c4626b7cda53580535c3140ce9c2a9
Status: Downloaded newer image for python:2-alpine

/ # apk add --no-cache gcc musl-dev
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
(1/13) Installing binutils-libs (2.30-r1)
(2/13) Installing binutils (2.30-r1)
(3/13) Installing gmp (6.1.2-r1)
(4/13) Installing isl (0.18-r0)
(5/13) Installing libgomp (6.4.0-r5)
(6/13) Installing libatomic (6.4.0-r5)
(7/13) Installing pkgconf (1.3.10-r0)
(8/13) Installing libgcc (6.4.0-r5)
(9/13) Installing mpfr3 (3.1.5-r1)
(10/13) Installing mpc1 (1.0.3-r1)
(11/13) Installing libstdc++ (6.4.0-r5)
(12/13) Installing gcc (6.4.0-r5)
(13/13) Installing musl-dev (1.1.18-r3)
Executing busybox-1.27.2-r11.trigger
OK: 110 MiB in 43 packages
/ # pip install numpy
Collecting numpy
  Using cached https://files.pythonhosted.org/packages/d5/6e/f00492653d0fdf6497a181a1c1d46bbea5a2383e7faf4c8ca6d6f3d2581d/numpy-1.14.5.zip
Building wheels for collected packages: numpy
  Running setup.py bdist_wheel for numpy ... done
  Stored in directory: /root/.cache/pip/wheels/8e/6f/1c/e089e6eef4d32bdd8a9ab9dfed2da700ebd383c3eb28a37b7d
Successfully built numpy
Installing collected packages: numpy
Successfully installed numpy-1.14.5

Issue is resolved, closing

Was this page helpful?
0 / 5 - 0 ratings