Error installing gevent in Docker Alpine Python

Question:

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('"'"'rn'"'"', '"'"'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.

Asked By: sur.la.route

||

Answers:

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.

Answered By: atline

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

Answered By: Song

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
Answered By: xmantas

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!

Answered By: Abhijeet Anand Shah

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

Answered By: Trevor Gross