Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lrodorigo opened this issue May 31, 2016 · 9 comments
Closed

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

lrodorigo opened this issue May 31, 2016 · 9 comments
Labels

Comments

@lrodorigo
Copy link

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.

@yosifkit
Copy link
Member

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. 😢

@tianon
Copy link
Member

tianon commented Aug 8, 2016

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
>>> 

@tianon tianon closed this as completed Aug 8, 2016
@tianon
Copy link
Member

tianon commented Aug 8, 2016

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

@tianon tianon reopened this Aug 8, 2016
@tianon
Copy link
Member

tianon commented Aug 8, 2016

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/

@tianon
Copy link
Member

tianon commented Aug 8, 2016

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

@thebrianbug
Copy link

thebrianbug commented Nov 8, 2016

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.

@AlJohri
Copy link

AlJohri commented Nov 15, 2016

@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?

@AlJohri
Copy link

AlJohri commented Nov 15, 2016

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.

@wglambert
Copy link

$ 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants