python - 无法使用 Dockerfile 安装 llvm-lite

标签 python docker dockerfile llvm llvmlite

下面的场景阻止我在 dockerize 我的 Flask 应用程序方面取得进展,有人对此有任何线索吗?下面的一些重要信息。
我已经看到关于设置 LLVM_CONFIG 文件到正确的路径,但在 docker 构建过程中是哪个路径以及如何做到这一点?

  • 点 20.2.3
  • python 3.8

  • 在 Dockerfile 下方:
    FROM python:3.8-alpine
    RUN adduser -D ddc-user
    WORKDIR /ddc
    COPY . /ddc
    RUN echo "http://dl-8.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
         && apk --no-cache --update-cache add postgresql-dev g++ linux-headers gfortran libffi-dev openssl-dev gcc build-base bash libpng-dev openblas-dev wget freetype-dev python3-dev py3-pip \
         && ln -s /usr/include/locale.h /usr/include/xlocale.h
    RUN apk --update add libxml2-dev libxslt-dev libffi-dev gcc musl-dev libgcc openssl-dev curl
    RUN apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev
    RUN pip install --upgrade pip
    RUN pip install Pillow
    RUN LLVM_CONFIG=/tmp/pip-install-3knaaqva/llvmlite/ffi/llvm-config pip install llvmlite==0.34.0
    RUN apk add --no-cache --virtual .build-deps gcc musl-dev
    RUN pip install numpy pyyaml
    RUN pip install setuptools wheel
    RUN pip install cython
    RUN pip install -r requirements.txt
    RUN chmod +x boot.sh
    ENV FLASK_APP main.py
    RUN chown -R ddc-user:users ./
    USER ddc-user
    EXPOSE 5000
    ENTRYPOINT ["./boot.sh"]
    
    在错误下方:
    Collecting llvmlite==0.34.0
      Downloading llvmlite-0.34.0.tar.gz (107 kB)
    Building wheels for collected packages: llvmlite
      Building wheel for llvmlite (setup.py): started
      Building wheel for llvmlite (setup.py): finished with status '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-pe4psx4_/llvmlite/setup.py'"'"'; __file__='"'"'/t
    mp/pip-install-pe4psx4_/llvmlite/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-skfgived
           cwd: /tmp/pip-install-pe4psx4_/llvmlite/
      Complete output (26 lines):
      running bdist_wheel
      /usr/local/bin/python /tmp/pip-install-pe4psx4_/llvmlite/ffi/build.py
    
      LLVM version... Traceback (most recent call last):
        File "/tmp/pip-install-pe4psx4_/llvmlite/ffi/build.py", line 105, in main_posix
          out = subprocess.check_output([llvm_config, '--version'])
        File "/usr/local/lib/python3.8/subprocess.py", line 411, in check_output
          return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
        File "/usr/local/lib/python3.8/subprocess.py", line 489, in run
          with Popen(*popenargs, **kwargs) as process:
        File "/usr/local/lib/python3.8/subprocess.py", line 854, in __init__
          self._execute_child(args, executable, preexec_fn, close_fds,
        File "/usr/local/lib/python3.8/subprocess.py", line 1702, in _execute_child
          raise child_exception_type(errno_num, err_msg, err_filename)
      FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-install-3knaaqva/llvmlite/ffi/llvm-config'
    
      During handling of the above exception, another exception occurred:
    
      Traceback (most recent call last):
        File "/tmp/pip-install-pe4psx4_/llvmlite/ffi/build.py", line 191, in <module>
          main()
        File "/tmp/pip-install-pe4psx4_/llvmlite/ffi/build.py", line 181, in main
          main_posix('linux', '.so')
        File "/tmp/pip-install-pe4psx4_/llvmlite/ffi/build.py", line 107, in main_posix
          raise RuntimeError("%s failed executing, please point LLVM_CONFIG "
      RuntimeError: /tmp/pip-install-3knaaqva/llvmlite/ffi/llvm-config failed executing, please point LLVM_CONFIG to the path for llvm-config
      error: command '/usr/local/bin/python' failed with exit status 1
      ----------------------------------------
      ERROR: Failed building wheel for llvmlite
    

    最佳答案

    首先, LLVM-Lite 需要 LLVM .
    所以,有必要安装 LLVM 正确地,要做到这一点:

    RUN apt-get update && apt-get install -y \
        build-essential \
        libedit-dev  \
        llvm-{version} \
        llvm-{version}-dev
    
    然后,设置构建时使用的环境变量 LLVM-Lite 并安装 pip包裹:
    RUN LLVM_CONFIG=/usr/bin/llvm-config-{version} pip install llvmlite=={version}
    
    这将解决您的问题。
    找出的哪个版本LLVM 兼容的各个版本LLVM-Lite 去:
  • https://github.com/numba/llvmlite#compatibility
  • 关于python - 无法使用 Dockerfile 安装 llvm-lite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64163244/

    相关文章:

    python - 吉时利 2410 和 PyVISA - VI_ERROR_TMO : Timeout expired before operation completed

    networking - Docker 接口(interface)在哪个 MAC 地址上连接互联网?

    docker-compose:为多个服务使用多个 Dockerfile

    node.js - 无法与简单的 Docker Node.js 网络应用程序通信

    docker - 如何限制 Docker 复制哪些目录和文件?

    Dockerfile, 如何安装 snap, snapd : unrecognized service

    python - 在python范围内查找素数

    python - 如何在Python中解码/编码十进制值?

    python - 使用 FastAPI 使用属性和 key 发出 POST 请求时出现 "422 Unprocessable Entity"错误

    docker - 无法连接到在本地 Docker 容器中运行的 Go GRPC 服务器