【问题标题】:How to install python2.6 in alpine container?如何在 alpine 容器中安装 python2.6?
【发布时间】:2017-04-11 09:34:07
【问题描述】:

如何在 alpine docker 容器中安装 python2.6。

我尝试从源代码安装,它给了我编译错误。

其实我想在容器中安装 Python2.6 和 Python2.7。这样我就可以在 Python2.6 和 Python2.7 上运行单元测试。请对此提出一些想法。

我已经在 alpine 容器中安装了 gcc 、 g++ 、 make 然后做了以下步骤。

wget https://www.python.org/ftp/python/2.6/Python-2.6.tgz
tar xvzf Python-2.6.tgz
cd Python-2.6
./configure
make

make 时遇到这个错误,

~/Python-2.6 # make
gcc -c -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes  -I. -IInclude -I./Include   -DPy_BUILD_CORE -o Modules/config.o Modules/config.c
gcc -c -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes  -I. -IInclude -I./Include   -DPy_BUILD_CORE -DPYTHONPATH='":plat-linux4:lib-tk:lib-old"' \
    -DPREFIX='"/usr/local"' \
    -DEXEC_PREFIX='"/usr/local"' \
    -DVERSION='"2.6"' \
    -DVPATH='""' \
    -o Modules/getpath.o ./Modules/getpath.c
gcc -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes  -I. -IInclude -I./Include   -DPy_BUILD_CORE  -c ./Modules/posixmodule.c -o Modules/posixmodule.o
./Modules/posixmodule.c:6173:1: error: conflicting types for 'posix_close'
 posix_close(PyObject *self, PyObject *args)
 ^
In file included from Include/Python.h:44:0,
                 from ./Modules/posixmodule.c:30:
/usr/include/unistd.h:38:5: note: previous declaration of 'posix_close' was here
 int posix_close(int, int);
     ^
Makefile:1234: recipe for target 'Modules/posixmodule.o' failed
make: *** [Modules/posixmodule.o] Error 1

谁能建议我如何解决这个问题?

【问题讨论】:

标签: python gcc docker alpine


【解决方案1】:

Docker 有一个official repos,使用起来非常方便。方便的是,有一个python 官方回购。它具有不同版本的 Python(包括 2.7)和不同的基本操作系统(包括 alpine)的图像。我建议使用官方的 2.7-alphine 映像并使用 its Dockerfile 作为安装 python 2.6 的参考。

我还建议使用单独的图像,一张使用 python 2.6,一张使用 2.7,而不是将两者都放在同一个图像中。这将有助于避免并排安装/配置两个不同版本的 python。


如果不查看 Dockerfile 的其余部分,很难说出为什么您的构建无法正常工作,但一个起点是构建依赖项。官方 Dockerfile 在 37-53 行添加了构建依赖项,该列表的依赖项比你说的安装的要多。

【讨论】:

    【解决方案2】:

    我设法通过调整这个问题的补丁来实现这个工作:https://bugs.python.org/issue20594 到 Python 2:

    --- ./Modules/posixmodule.c.orig
    +++ ./Modules/posixmodule.c
    @@ -3896,7 +3896,7 @@
     #endif
         gid_t grouplist[MAX_GROUPS];
    
    -    /* On MacOSX getgroups(2) can return more than MAX_GROUPS results
    +    /* On MacOSX getgroups(2) can return more than MAX_GROUPS results
          * This is a helper variable to store the intermediate result when
          * that happens.
          *
    @@ -6357,7 +6357,7 @@
     Close a file descriptor (for low level IO).");
    
     static PyObject *
    -posix_close(PyObject *self, PyObject *args)
    +posix_closex(PyObject *self, PyObject *args)
     {
         int fd, res;
         if (!PyArg_ParseTuple(args, "i:close", &fd))
    @@ -8602,7 +8602,7 @@
         {"tcsetpgrp",       posix_tcsetpgrp, METH_VARARGS, posix_tcsetpgrp__doc__},
     #endif /* HAVE_TCSETPGRP */
         {"open",            posix_open, METH_VARARGS, posix_open__doc__},
    -    {"close",           posix_close, METH_VARARGS, posix_close__doc__},
    +    {"close",           posix_closex, METH_VARARGS, posix_close__doc__},
         {"closerange",      posix_closerange, METH_VARARGS, posix_closerange__doc__},
         {"dup",             posix_dup, METH_VARARGS, posix_dup__doc__},
         {"dup2",            posix_dup2, METH_VARARGS, posix_dup2__doc__},
    

    我在这里发布了完整的 Dockerfile 和补丁:

    https://gist.github.com/cwill747/722f41d8807c3b41a1e417849634cfe5

    【讨论】:

      【解决方案3】:

      对于python2.7,你可以使用frolvlad/alpine-python2,这是一个基于alpine的50MB python2.7镜像。

      对于 python2.6,您可以获取 Dockerfile 并对其进行更新,以便它也适用于该版本

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-01-17
        • 1970-01-01
        • 2017-07-14
        • 2021-02-19
        • 2016-06-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多