Error installing gevent in Docker Alpine Python
Asked Answered
F

5

6

I'm trying to install gevent on docker image python:3.8.0a4-alpine3.9 which is running gunicorn.

When building the docker, I always get an error "gcc failed with exit status 1".

I've tried installing several packages but none have worked.

Here is the Dockerfile:

FROM python:3.8.0a4-alpine3.9

RUN echo "@edge-community http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
  apk update && \
  apk add build-base python-dev && \
  apk add py-gevent

RUN pip install gunicorn gevent

command: docker build . -t "test:one"

Last few lines of output:


  /usr/local/include/python3.8/code.h:105:28: note: expected 'PyObject *' {aka 'struct _object *'} but argument is of type 'int'
   PyAPI_FUNC(PyCodeObject *) PyCode_New(
                              ^~~~~~~~~~
  src/gevent/libev/corecext.c:21340:9: warning: passing argument 15 of 'PyCode_New' makes integer from pointer without a cast [-Wint-conversion]
           __pyx_empty_bytes  /*PyObject *lnotab*/
           ^~~~~~~~~~~~~~~~~
  src/gevent/libev/corecext.c:373:79: note: in definition of macro '__Pyx_PyCode_New'
             PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
                                                                                 ^~~~
  In file included from /usr/local/include/python3.8/compile.h:5,
                   from /usr/local/include/python3.8/Python.h:137,
                   from src/gevent/libev/corecext.c:63:
  /usr/local/include/python3.8/code.h:105:28: note: expected 'int' but argument is of type 'PyObject *' {aka 'struct _object *'}
   PyAPI_FUNC(PyCodeObject *) PyCode_New(
                              ^~~~~~~~~~
  src/gevent/libev/corecext.c:373:11: error: too few arguments to function 'PyCode_New'
             PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
             ^~~~~~~~~~
  src/gevent/libev/corecext.c:21325:15: note: in expansion of macro '__Pyx_PyCode_New'
       py_code = __Pyx_PyCode_New(
                 ^~~~~~~~~~~~~~~~
  In file included from /usr/local/include/python3.8/compile.h:5,
                   from /usr/local/include/python3.8/Python.h:137,
                   from src/gevent/libev/corecext.c:63:
  /usr/local/include/python3.8/code.h:105:28: note: declared here
   PyAPI_FUNC(PyCodeObject *) PyCode_New(
                              ^~~~~~~~~~
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for gevent
  Running setup.py clean for gevent

...
lots of stuff
...


out a cast [-Wint-conversion]
             __pyx_empty_bytes  /*PyObject *lnotab*/
             ^~~~~~~~~~~~~~~~~
    src/gevent/libev/corecext.c:373:79: note: in definition of macro '__Pyx_PyCode_New'
               PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
                                                                                   ^~~~
    In file included from /usr/local/include/python3.8/compile.h:5,
                     from /usr/local/include/python3.8/Python.h:137,
                     from src/gevent/libev/corecext.c:63:
    /usr/local/include/python3.8/code.h:105:28: note: expected 'int' but argument is of type 'PyObject *' {aka 'struct _object *'}
     PyAPI_FUNC(PyCodeObject *) PyCode_New(
                                ^~~~~~~~~~
    src/gevent/libev/corecext.c:373:11: error: too few arguments to function 'PyCode_New'
               PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
               ^~~~~~~~~~
    src/gevent/libev/corecext.c:21325:15: note: in expansion of macro '__Pyx_PyCode_New'
         py_code = __Pyx_PyCode_New(
                   ^~~~~~~~~~~~~~~~
    In file included from /usr/local/include/python3.8/compile.h:5,
                     from /usr/local/include/python3.8/Python.h:137,
                     from src/gevent/libev/corecext.c:63:
    /usr/local/include/python3.8/code.h:105:28: note: declared here
     PyAPI_FUNC(PyCodeObject *) PyCode_New(
                                ^~~~~~~~~~
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command "/usr/local/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-3i9v17bs/gevent/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-gnyfyggo/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-3i9v17bs/gevent/

Here is the Gunicorn command I am running:

gunicorn web.wsgi:application --bind 0.0.0.0:8000  --worker-connections 1000 --workers 6 -k gevent

Do you have any ideas on how to install Gevent with this version of python alpine?

Edit - It installs successfully on the last version of Alpine and python - FROM python:3.7-alpine3.8.

Florist answered 3/6, 2019 at 17:54 Comment(0)
E
2

See this, years ago, guys want to install on python3.7 and encountered issue, and fix was made on last year to make gevent support python3.7.

So, I guess gevent team need additional effort to adapt to every python version as its principle is to make some monkey patch for python.

And, from its current official announcement, it said:

gevent 1.5 runs on Python 2.7.9 and up, and Python 3.5, 3.6 and 3.7.

It did not mention 3.8, so definitely you need to wait.

England answered 4/6, 2019 at 2:42 Comment(1)
For those who like me reached this post looking for a fix for failed build on a windows machine, don't ignore the Notice about windows in the official announcement link. It won't build on your windows machine if its not already, have a good day!Lonergan
L
15

ailpine image need install below libs to build gevent.
RUN apk add --no-cache python3-dev libffi-dev gcc musl-dev make
this docker file may help to test

Luau answered 17/4, 2020 at 5:11 Comment(2)
Thank you sir! I was missing make, on alpine 3.7.7. For anyone wondering at this time of writing python 3.8 is not supported for gevent, no matter alpine or not. If you are using a a docker builder image, make sure you put both images in the dockerfile on the same version :)Diastase
This helped me even though I did not use that image. Using python:3.6.5-slim gevent would fail. I added the above requirements as well as libevent-dev and the install passes.Szechwan
I
5

To me none of the above worked with python:3.8-alpine. Worked this:

RUN apk --update --no-cache add python3-dev libffi-dev gcc musl-dev make libevent-dev build-base
Introject answered 5/4, 2021 at 11:56 Comment(2)
I tried to reduce the list and finally, only build-base is required.Electret
just add build-base. worked for me on python:3.8.10-alpine3.13Lacombe
E
2

See this, years ago, guys want to install on python3.7 and encountered issue, and fix was made on last year to make gevent support python3.7.

So, I guess gevent team need additional effort to adapt to every python version as its principle is to make some monkey patch for python.

And, from its current official announcement, it said:

gevent 1.5 runs on Python 2.7.9 and up, and Python 3.5, 3.6 and 3.7.

It did not mention 3.8, so definitely you need to wait.

England answered 4/6, 2019 at 2:42 Comment(1)
For those who like me reached this post looking for a fix for failed build on a windows machine, don't ignore the Notice about windows in the official announcement link. It won't build on your windows machine if its not already, have a good day!Lonergan
N
2

I am using gevent==21.1.2 with python:3.9.4-alpine by adding

RUN apk update \
   && apk add --no-cache build-base

It worked like a charm!

Needful answered 19/5, 2021 at 15:32 Comment(0)
S
1

Good news: As of gevent 21.12.0 (released 2021-12-11), there is a musllinux image on pypi, so there are no missing dependencies and it will install from wheel. Verified on python3.10-alpine that pip install gevent works fine. Woohoo!

Historical answer, see below.


Just adding on here: for python:3.9-alpine (which is currently python3.9.9 + alpine 3.14.3), I needed the following for Gevent 21.1.0:

RUN apk add --no-cache build-base libffi-dev

Hopefully they add support for installing on Alpine via pip since there is a recent PEP that should make this easier. I opened an issue here: https://github.com/gevent/gevent/issues/1837

Sledge answered 2/12, 2021 at 5:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.