如何在 Alpine Docker 容器中安装 multidict 时修复 gcc 错误?

4

问:在我的Docker容器中,我使用了预安装了gcc的alpine Linux系统。

apk信息:

bash-4.4# apk info
....
gcc

但是当我安装multidict时,遇到了gcc错误。

bash-4.4# pip install multidict
Collecting multidict
  Using cached https://files.pythonhosted.org/packages/84/96/5503ba866d8d216e49a6ce3bcb288df8a5fb3ac8a90b8fcff9ddcda32568/multidict-4.7.3.tar.gz
Building wheels for collected packages: multidict
  Building wheel for multidict (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-79jceuft/multidict/setup.py'"'"'; __file__='"'"'/tmp/pip-install-79jceuft/multidict/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-57k4lw21 --python-tag cp37
       cwd: /tmp/pip-install-79jceuft/multidict/
 ....
    /usr/local/include/python3.7m/Python.h:11:20: fatal error: limits.h: No such file or directory
     #include <limits.h>
                        ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-79jceuft/multidict/setup.py'"'"'; __file__='"'"'/tmp/pip-install-79jceuft/multidict/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-lomj_vmk/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.

我该怎么解决这个问题?


这个答案有帮助吗? - kopecs
我已经修复了它。 - ZosionLee
安装musl-dev。 - ZosionLee
3个回答

6
简单的解决方法是在dockerfile中添加以下命令:
RUN apk --no-cache add gcc musl-dev

thanks to @Zosionlee for hint.


4

预安装GCC和其他环境。

例如:

RUN apk update \
    && apk add --no-cache gcc git python3-dev musl-dev linux-headers  
    libc-dev  rsync zsh \
    findutils wget util-linux grep libxml2-dev libxslt-dev \
    &&  pip3 install --upgrade pip

1

我遇到了这个问题,但是解决方法并不需要在系统上使用sudo安装:

$ pip install --upgrade pip setuptools-scm

我也是在虚拟环境中完成的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接