python - 无法使用 sasl python 模块构建 docker 镜像

标签 python macos docker pip

我正在尝试在我的 mac (High Sierra) 上构建一个包含 Python 2 的 docker 镜像。这是 docker 文件。 (构建命令:docker build -t integration_test .)

FROM python:2

WORKDIR /usr/src/app

COPY requirements.txt ./

RUN pip install -r requirements.txt

COPY . .

CMD [ "nosetests" ]

这是requirements.txt

的内容
nose
pyhive
thrift
sasl
thrift_sasl
python-dateutil
future
six>=1.7.2

当我尝试构建 docker 镜像时,出现以下错误。

Failed building wheel for sasl
  Running setup.py clean for sasl
  Running setup.py bdist_wheel for thrift-sasl: started
  Running setup.py bdist_wheel for thrift-sasl: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/c8/3a/34/1d82df3d652788fc211c245d51dde857a58e603695ea41d93d
  Running setup.py bdist_wheel for future: started
  Running setup.py bdist_wheel for future: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/bf/c9/a3/c538d90ef17cf7823fa51fc701a7a7a910a80f6a405bf15b1a
Successfully built pyhive thrift thrift-sasl future
Failed to build sasl
Installing collected packages: nose, future, six, python-dateutil, pyhive, thrift, sasl, thrift-sasl
  Running setup.py install for sasl: started
    Running setup.py install for sasl: finished with status 'error'
    Complete output from command /usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-Dd4Z7v/sasl/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-_rw4YI/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    creating build/lib.linux-x86_64-2.7/sasl
    copying sasl/__init__.py -> build/lib.linux-x86_64-2.7/sasl
    running egg_info
    writing requirements to sasl.egg-info/requires.txt
    writing sasl.egg-info/PKG-INFO
    writing top-level names to sasl.egg-info/top_level.txt
    writing dependency_links to sasl.egg-info/dependency_links.txt
    reading manifest file 'sasl.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'sasl.egg-info/SOURCES.txt'
    copying sasl/saslwrapper.cpp -> build/lib.linux-x86_64-2.7/sasl
    copying sasl/saslwrapper.h -> build/lib.linux-x86_64-2.7/sasl
    copying sasl/saslwrapper.pyx -> build/lib.linux-x86_64-2.7/sasl
    running build_ext
    building 'sasl.saslwrapper' extension
    creating build/temp.linux-x86_64-2.7
    creating build/temp.linux-x86_64-2.7/sasl
    gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Isasl -I/usr/local/include/python2.7 -c sasl/saslwrapper.cpp -o build/temp.linux-x86_64-2.7/sasl/saslwrapper.o
    cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
    In file included from sasl/saslwrapper.cpp:254:0:
    sasl/saslwrapper.h:22:23: fatal error: sasl/sasl.h: No such file or directory
     #include <sasl/sasl.h>
                           ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-Dd4Z7v/sasl/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-_rw4YI/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-Dd4Z7v/sasl/
The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1

我见过类似的问题here它讨论了在主机操作系统上安装依赖库。我想知道如何在 docker image/container 上完成此操作。

有没有人遇到过这个问题?关于如何解决这个问题有什么建议吗?

最佳答案

您需要将 libsasl2-dev 安装到您的 Docker 镜像。

以最简单的形式,在 pip install 之前将以下行添加到您的 Dockerfile 中:

RUN apt-get update && apt-get install libsasl2-dev

关于python - 无法使用 sasl python 模块构建 docker 镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52365838/

相关文章:

python - 循环数据帧并生成汇总统计数据时出现问题

Python 正则表达式 : include an entire field

angular - Angular + Kubernetes + Nginx上的路由问题

.net - 在 ASP.NET Core : "no such file or directory" error 中构建 docker

python - 线程中的 pyGame

python - 如何在两个字符串之间进行模式匹配?

java - Intellij 无法解决传递依赖

c++ - 构建 python 模块并将其与 MacOSX 框架链接

c++ - 安装 Boost C++ 时遇到问题

mongodb - Docker +主管:如何初始化服务(mongo&elasticmq)?