在 Docker Alpine Python 中安装 gevent 时出错
Error installing gevent in Docker Alpine Python
我正在尝试在 docker 图像 python:3.8.0a4-alpine3.9
上安装 gevent,它是 运行 gunicorn。
构建 docker 时,我总是收到错误“gcc 失败,退出状态为 1”。
我尝试安装了几个软件包,但 none 成功了。
这是 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
.
上成功安装
请参阅 this,几年前,有人想在 python3.7 上安装并遇到问题,去年进行了修复以使 gevent
支持 python3.7.
所以,我猜 gevent 团队需要额外的努力来适应每个 python 版本,因为它的原则是为 python.
制作一些 monkey patch
而且,从目前的 official announcement,它说:
gevent 1.5 runs on Python 2.7.9 and up, and Python 3.5, 3.6 and 3.7.
它没有提到3.8,所以你肯定需要等待。
ailpine 镜像需要安装在 libs 下面来构建 gevent。
RUN apk add --no-cache python3-dev libffi-dev gcc musl-dev make
this docker file 可能有助于测试
对我来说 none 以上与 python:3.8-alpine
一起工作。工作了这个:
RUN apk --update --no-cache add python3-dev libffi-dev gcc musl-dev make libevent-dev build-base
我通过添加
将 gevent==21.1.2
与 python:3.9.4-alpine
一起使用
RUN apk update \
&& apk add --no-cache build-base
效果非常好!
好消息:从gevent 21.12.0(2021-12-11发布)开始,pypi上有一个musllinux镜像,所以没有缺失的依赖,它将从轮子安装。在 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
我正在尝试在 docker 图像 python:3.8.0a4-alpine3.9
上安装 gevent,它是 运行 gunicorn。
构建 docker 时,我总是收到错误“gcc 失败,退出状态为 1”。
我尝试安装了几个软件包,但 none 成功了。
这是 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
.
请参阅 this,几年前,有人想在 python3.7 上安装并遇到问题,去年进行了修复以使 gevent
支持 python3.7.
所以,我猜 gevent 团队需要额外的努力来适应每个 python 版本,因为它的原则是为 python.
制作一些monkey patch
而且,从目前的 official announcement,它说:
gevent 1.5 runs on Python 2.7.9 and up, and Python 3.5, 3.6 and 3.7.
它没有提到3.8,所以你肯定需要等待。
ailpine 镜像需要安装在 libs 下面来构建 gevent。
RUN apk add --no-cache python3-dev libffi-dev gcc musl-dev make
this docker file 可能有助于测试
对我来说 none 以上与 python:3.8-alpine
一起工作。工作了这个:
RUN apk --update --no-cache add python3-dev libffi-dev gcc musl-dev make libevent-dev build-base
我通过添加
将gevent==21.1.2
与 python:3.9.4-alpine
一起使用
RUN apk update \
&& apk add --no-cache build-base
效果非常好!
好消息:从gevent 21.12.0(2021-12-11发布)开始,pypi上有一个musllinux镜像,所以没有缺失的依赖,它将从轮子安装。在 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