【问题标题】:Error installing gevent in Docker Alpine Python在 Docker Alpine Python 中安装 gevent 时出错
【发布时间】:2019-10-19 07:13:45
【问题描述】:

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

在构建 docker 时,我总是收到错误“gcc failed with exit status 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/

这是我正在运行的 Gunicorn 命令:

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

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

编辑 - 它在最后一个版本的 Alpine 和 python - FROM python:3.7-alpine3.8 上成功安装。

【问题讨论】:

    标签: python-3.x docker alpine


    【解决方案1】:

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

    【讨论】:

    • 谢谢先生!我在 alpine 3.7.7 上错过了 make。对于任何想知道在编写 python 3.8 时不支持 gevent 的人,无论是否高山。如果您使用的是 docker builder 镜像,请确保将两个镜像放在同一版本的 dockerfile 中:)
    • 这对我有帮助,即使我没有使用该图像。使用 python:3.6.5-slim gevent 会失败。我添加了上述要求以及libevent-dev 和安装通行证。
    【解决方案2】:

    对我来说,以上都不适用于python:3.8-alpine。工作过:

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

    【讨论】:

    • 我尝试减少列表,最后只需要build-base
    • 只需添加构建基础。在 python:3.8.10-alpine3.13 上为我工作
    【解决方案3】:

    参见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,所以你肯定需要等待。

    【讨论】:

    • 对于那些像我一样到达这篇文章寻找修复在 windows 机器上失败的构建的人,不要忽略官方公告链接中关于 windows 的通知。 如果它还没有,它不会在你的 Windows 机器上构建,祝你有美好的一天!
    【解决方案4】:

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

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

    它就像一个魅力!

    【讨论】:

      【解决方案5】:

      好消息: 从 gevent 21.12.0(2021-12-11 发布)开始,pypi 上有一个 musllinux 映像,因此没有缺少依赖项,它将从 wheel 安装。在 python3.10-alpine 上验证 pip install gevent 工作正常。哇哦!

      历史答案,见下文。


      在这里添加:对于 python:3.9-alpine(目前是 python3.9.9 + alpine 3.14.3),我需要 Gevent 21.1.0 的以下内容:

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

      希望他们增加了对通过 pip 在 Alpine 上安装的支持,因为最近有一个 PEP 可以让这更容易。我在这里打开了一个问题:https://github.com/gevent/gevent/issues/1837

      【讨论】:

        猜你喜欢
        • 2017-05-25
        • 2019-07-20
        • 1970-01-01
        • 2018-09-29
        • 1970-01-01
        • 1970-01-01
        • 2020-01-07
        • 2016-01-30
        • 2016-11-28
        相关资源
        最近更新 更多