Python: Unable to install Cython on alpine image

Created on 16 Jul 2018  路  4Comments  路  Source: docker-library/python

I think something is missing, but can't understand what.
Trying it on the python:3.6-alpine3.7 image.

While running pip install Cython, I'm getting this error:

gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/local/include/python3.6m -c /tmp/pip-install-zsnsb46v/Cython/Cython/Plex/Scanners.c -o build/temp.linux-x86_64-3.6/tmp/pip-install-zsnsb46v/Cython/Cython/Plex/Scanners.o unable to execute 'gcc': No such file or directory error: command 'gcc' failed with exit status 1

Any help will be appreciated :)

question

Most helpful comment

unable to execute 'gcc': No such file or directory error: command 'gcc' failed with exit status 1

You need gcc, the preferred way of handling this is with a Dockerfile to install dependencies and then removing them afterwards all in one layer (else the image size will be about 100MB higher otherwise)

FROM python:3.6-alpine

RUN apk add --no-cache --virtual .build-deps gcc musl-dev \
 && pip install cython \
 && apk del .build-deps
$ docker build . -t python:test
Sending build context to Docker daemon  3.584kB
Step 1/2 : FROM python:3.6-alpine
 ---> 148efb059c7f
Step 2/2 : RUN apk add --no-cache --virtual .build-deps gcc musl-dev  && pip install cython  && apk del .build-deps
 ---> Running in 857a2a6e9ad8
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/12) Installing binutils (2.31.1-r2)
(2/12) Installing gmp (6.1.2-r1)
(3/12) Installing isl (0.18-r0)
(4/12) Installing libgomp (8.3.0-r0)
(5/12) Installing libatomic (8.3.0-r0)
(6/12) Installing libgcc (8.3.0-r0)
(7/12) Installing mpfr3 (3.1.5-r1)
(8/12) Installing mpc1 (1.0.3-r1)
(9/12) Installing libstdc++ (8.3.0-r0)
(10/12) Installing gcc (8.3.0-r0)
(11/12) Installing musl-dev (1.1.20-r4)
(12/12) Installing .build-deps (0)
Executing busybox-1.29.3-r10.trigger
OK: 115 MiB in 46 packages
Collecting cython
  Downloading https://files.pythonhosted.org/packages/f8/da/c979464858b257b21a6472a85285548c91f5b4dc773cb049cfdfb3ceeb02/Cython-0.29.7.tar.gz (2.0MB)
Building wheels for collected packages: cython
  Building wheel for cython (setup.py): started
  Building wheel for cython (setup.py): still running...
  Building wheel for cython (setup.py): finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/79/b9/15/c589b51f4e91b37faa76362180166a2041e4286c38dbc45fc6
Successfully built cython
Installing collected packages: cython
Successfully installed cython-0.29.7
WARNING: Ignoring APKINDEX.b89edf6e.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.737f7e01.tar.gz: No such file or directory
(1/12) Purging .build-deps (0)
(2/12) Purging gcc (8.3.0-r0)
(3/12) Purging binutils (2.31.1-r2)
(4/12) Purging libatomic (8.3.0-r0)
(5/12) Purging libgomp (8.3.0-r0)
(6/12) Purging musl-dev (1.1.20-r4)
(7/12) Purging mpc1 (1.0.3-r1)
(8/12) Purging mpfr3 (3.1.5-r1)
(9/12) Purging isl (0.18-r0)
(10/12) Purging gmp (6.1.2-r1)
(11/12) Purging libstdc++ (8.3.0-r0)
(12/12) Purging libgcc (8.3.0-r0)
Executing busybox-1.29.3-r10.trigger
OK: 18 MiB in 34 packages
Removing intermediate container 857a2a6e9ad8
 ---> d7415049e2e8
Successfully built d7415049e2e8
Successfully tagged python:test
$ docker run --rm python:test pip freeze
Cython==0.29.7

All 4 comments

unable to execute 'gcc': No such file or directory error: command 'gcc' failed with exit status 1

You need gcc, the preferred way of handling this is with a Dockerfile to install dependencies and then removing them afterwards all in one layer (else the image size will be about 100MB higher otherwise)

FROM python:3.6-alpine

RUN apk add --no-cache --virtual .build-deps gcc musl-dev \
 && pip install cython \
 && apk del .build-deps
$ docker build . -t python:test
Sending build context to Docker daemon  3.584kB
Step 1/2 : FROM python:3.6-alpine
 ---> 148efb059c7f
Step 2/2 : RUN apk add --no-cache --virtual .build-deps gcc musl-dev  && pip install cython  && apk del .build-deps
 ---> Running in 857a2a6e9ad8
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/12) Installing binutils (2.31.1-r2)
(2/12) Installing gmp (6.1.2-r1)
(3/12) Installing isl (0.18-r0)
(4/12) Installing libgomp (8.3.0-r0)
(5/12) Installing libatomic (8.3.0-r0)
(6/12) Installing libgcc (8.3.0-r0)
(7/12) Installing mpfr3 (3.1.5-r1)
(8/12) Installing mpc1 (1.0.3-r1)
(9/12) Installing libstdc++ (8.3.0-r0)
(10/12) Installing gcc (8.3.0-r0)
(11/12) Installing musl-dev (1.1.20-r4)
(12/12) Installing .build-deps (0)
Executing busybox-1.29.3-r10.trigger
OK: 115 MiB in 46 packages
Collecting cython
  Downloading https://files.pythonhosted.org/packages/f8/da/c979464858b257b21a6472a85285548c91f5b4dc773cb049cfdfb3ceeb02/Cython-0.29.7.tar.gz (2.0MB)
Building wheels for collected packages: cython
  Building wheel for cython (setup.py): started
  Building wheel for cython (setup.py): still running...
  Building wheel for cython (setup.py): finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/79/b9/15/c589b51f4e91b37faa76362180166a2041e4286c38dbc45fc6
Successfully built cython
Installing collected packages: cython
Successfully installed cython-0.29.7
WARNING: Ignoring APKINDEX.b89edf6e.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.737f7e01.tar.gz: No such file or directory
(1/12) Purging .build-deps (0)
(2/12) Purging gcc (8.3.0-r0)
(3/12) Purging binutils (2.31.1-r2)
(4/12) Purging libatomic (8.3.0-r0)
(5/12) Purging libgomp (8.3.0-r0)
(6/12) Purging musl-dev (1.1.20-r4)
(7/12) Purging mpc1 (1.0.3-r1)
(8/12) Purging mpfr3 (3.1.5-r1)
(9/12) Purging isl (0.18-r0)
(10/12) Purging gmp (6.1.2-r1)
(11/12) Purging libstdc++ (8.3.0-r0)
(12/12) Purging libgcc (8.3.0-r0)
Executing busybox-1.29.3-r10.trigger
OK: 18 MiB in 34 packages
Removing intermediate container 857a2a6e9ad8
 ---> d7415049e2e8
Successfully built d7415049e2e8
Successfully tagged python:test
$ docker run --rm python:test pip freeze
Cython==0.29.7

Well, that's embarrassing.
Spent about 30 mins before opening this issue, going over Cython's source code to see what is going on with that Scanners class totally mislead by the command 'gcc' failed with exit status 1 message.
Thank you for your help :)

the preferred way of handling this is with a Dockerfile to install dependencies and then removing them afterwards

FROM python:3.6-alpine

RUN apk add --no-cache --virtual .build-deps gcc musl-dev
RUN pip install cython
RUN apk del .build-deps gcc musl-dev

Just a quick comment to point out that using the 3 RUN commands above to delete dependencies will not make your image smaller, because it creates 3 different layers for the image.

To effectively save space by removing the installed build dependencies, the 3 commands needs to be ran into one single RUN command, which creates a single layer:

FROM python:3.6-alpine

RUN apk add --no-cache --virtual .build-deps gcc musl-dev \
    && pip install cython \
    && apk del .build-deps

also, .builddeps is the ref to the build deps listed, so no need to list them again.

Resulting image size:

python  3.6-alpine               79.1MB
cython  latest                       112MB
cython 3run                          212MB

If the above doesn't work for others, try installing python3-dev (or python2-dev as appropriate) in addition to gcc and musl-dev.

apk add gcc musl-dev python3-dev

pip3 install cython
Was this page helpful?
0 / 5 - 0 ratings

Related issues

zybjcdl picture zybjcdl  路  4Comments

ethanabrooks picture ethanabrooks  路  4Comments

ElianoMarques picture ElianoMarques  路  5Comments

ezawadzki picture ezawadzki  路  3Comments

ncopa picture ncopa  路  3Comments