在Docker Apline Python中安装Gevent时出错

时间:2019-06-03 17:54:28

标签: python-3.x docker alpine

我正在尝试在运行gunicorn的docker python:3.8.0a4-alpine3.9上安装Gevent。

构建docker时,总是会收到错误消息“ gcc失败,退出状态为1”。

我尝试安装多个软件包,但没有一个起作用。

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

命令: docker build . -t "test:one"

最后几行输出:


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

这是我正在运行的Gun​​icorn命令:

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

您对如何使用此版本的python alpine安装Gevent有任何想法吗?

编辑- 它成功安装在Apline和python的最新版本上-FROM python:3.7-alpine3.8

4 个答案:

答案 0 :(得分:11)

ailpine映像需要在libs下安装以构建gevent。
RUN apk add --no-cache python3-dev libffi-dev gcc musl-dev make
this docker file可能有助于测试

答案 1 :(得分:3)

对我来说,以上都不适用于 python:3.8-alpine。这样做了:

RUN apk --update --no-cache add python3-dev libffi-dev gcc musl-dev make libevent-dev build-base

答案 2 :(得分:1)

我通过添加将 gevent==21.1.2python:3.9.4-alpine 结合使用

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

它就像一个魅力!

答案 3 :(得分:0)

请参阅this,几年前,人们想在python3.7上安装并遇到问题,并且在去年进行了修复,以使gevent支持python3.7。

所以,我想gevent团队需要付出更多的努力来适应每个python版本,因为其原理是为python制作一些monkey patch

并且,从当前的official announcement开始,它说:

  

gevent 1.5在Python 2.7.9及更高版本以及Python 3.5、3.6和3.7上运行。

它没有提到3.8,所以绝对需要等待。