【问题标题】:Failed to install pyorc on alpine docker container无法在 alpine docker 容器上安装 pyorc
【发布时间】:2020-10-17 04:32:59
【问题描述】:

出现编译错误 - 这取决于 ORC 二进制文件。

In file included from src/_pyorc/_pyorc.cpp:1:
src/_pyorc/Reader.h:7:10: fatal error: 'orc/OrcFile.hh' file not found
#include "orc/OrcFile.hh"
         ^~~~~~~~~~~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1

如果我也单独编译 apache-orc,我如何将它的引用提供给 PyOrc Pip 安装?

任何人都有任何解决方案或想法,我们如何在 alpine 容器中安装 pyorc 包。

我在使用 ubuntu 的 alpine 映像和普通的 python docker 映像运行良好时遇到问题。

Docker 镜像:FROM python:3.7-alpine

【问题讨论】:

    标签: python docker compiler-errors alpine orc


    【解决方案1】:

    我使用了 Docker 多阶段构建:

    # Dockerfile
    
    FROM python:3.7.3
    WORKDIR /app
    RUN pip install pyorc -t .
    
    FROM python:3.7.3-alpine
    WORKDIR /app
    RUN apk add --no-cache --virtual .build-deps g++ musl-dev gcompat
    COPY --from=0 /app .
    

    它似乎工作:

    $ docker build -t test .
    $ docker run -it --rm test python
    Python 3.7.3 (default, Jun 27 2019, 22:53:21)
    [GCC 8.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pyorc
    >>>
    >>> with open("./new_data.orc", "wb") as data:
    ...     with pyorc.Writer(data, "struct<col0:int,col1:string>") as writer:
    ...         writer.write((1, "ORC from Python"))
    ...
    >>> from pathlib import Path
    >>> Path("./new_data.orc").read_bytes()
    b'ORC\x1d\x00\x00\n\x0c\n\x04\x00\x00\x.....'
    

    【讨论】:

    • 是的,具体来说我的问题是我必须使用 Alpine-Python3 而不是 python:3.7.3 即 FROM python:3.7-alpine
    【解决方案2】:

    作者 Noirello,给了我如下指南/方向:

    对于 Alpine,必须从源代码安装它。 文档中有一些说明如何操作:pyOrc-Docs

    我会使用多阶段的 Dockerfile 来构建 pyorc,然后将轮子与您的应用程序的其余部分一起安装到干净的 Alpine 映像中。

    类似这样的:

    FROM python:3.8.3-alpine AS builder
    RUN apk add gcc g++ musl-dev cmake make
    ARG VERSION=0.3.0
    
    RUN mkdir build
    WORKDIR /build
    RUN pip install pybind11 wheel
    RUN pip download --no-binary :all: --no-deps pyorc==${VERSION} && tar -xvf *.tar.gz
    RUN cd pyorc-${VERSION} && python3 setup.py build_orc
    RUN cd pyorc-${VERSION} && python3 setup.py bdist_wheel
    
    FROM python:3.8.3-alpine
    ARG VERSION=0.3.0
    
    COPY --from=builder /build/pyorc-${VERSION}/dist/pyorc-${VERSION}-*.whl /tmp/
    # Adding libstdc++, because the wheel expects that the libstdc++.so is presented on the system.
    # Adding tzdata, because the ORC C++ lib needs to have a localtime set.
    RUN apk add libstdc++ tzdata
    # Setting localtime to UTC.
    RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
    RUN pip install /tmp/pyorc-${VERSION}-*.whl && rm -rf /tmp/pyorc-${VERSION}-*.whl
    # Rest of your custom image...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-11
      • 2018-07-13
      • 2017-07-14
      • 1970-01-01
      • 2019-02-23
      • 2020-01-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多