简体   繁体   English

构建 docker 图像时出现 numpy 依赖问题

[英]Issue with numpy dependency when building docker image

I am trying to create a Sagemaker endpoint for model inference using the Build your own algorithm container ( https://sagemaker-examples.readthedocs.io/en/latest/advanced_functionality/scikit_bring_your_own/scikit_bring_your_own.html ) but am having an issue when installing Numpy in the creation of the image.我正在尝试使用构建自己的算法容器 ( https://sagemaker-examples.readthedocs.io/en/latest/advanced_functionality/scikit_bring_your_own/scikit_bring_your_own.html ) 为 model 推理创建一个 Sagemaker 端点,但在安装时遇到问题Numpy在创建镜像。

We've already previously have gotten it to work with our old model, but the new vowpal wabbit model requires numpy, scikit-learn, pandas and vowpal wabbit library which is causing it to fail in the docker build.我们之前已经让它与我们的旧 model 一起使用,但是新的 vowpal wabbit model 需要 numpy、scikit-learn、pandas 和 vowpal wabbit 库,这导致它在 88408658722 中失败I'm not sure if we should continue using this container or should migrate to a python one or sagemaker one, but would need to support nginx.我不确定我们是应该继续使用这个容器,还是应该迁移到 python 或 sagemaker,但需要支持 nginx。

#EDIT: Forgot to mention that when I build it locally, it is created successfully but when fails through Cloudformation. #EDIT:忘记提及当我在本地构建它时,它创建成功但通过 Cloudformation 失败时。

Dockerfile here: Dockerfile 这里:

# This is a Python 3 image that uses the nginx, gunicorn, flask stack
# for serving inferences in a stable way.
FROM ubuntu:18.04

# Retrieves information about what packages can be installed
RUN apt-get -y update && \
    apt-get install -y --no-install-recommends \
        wget \
        python3-pip \
        python3.8 \
        python3-setuptools \
        nginx \
        ca-certificates && \
    rm -rf /var/lib/apt/lists/*

# Set python 3.8 as default
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1

# Get all python packages without excess cache created by pip.
COPY requirements.txt .
RUN pip3 install --upgrade pip setuptools wheel
RUN pip3 --no-cache-dir install -r requirements.txt

# Set some environment variables. PYTHONUNBUFFERED keeps Python from buffering our standard
# model_output stream, which means that logs can be delivered to the user quickly. PYTHONDONTWRITEBYTECODE
# keeps Python from writing the .pyc files which are unnecessary in this case. We also update
# PATH so that the train and serve programs are found when the container is invoked.
ENV PYTHONUNBUFFERED=TRUE
ENV PYTHONDONTWRITEBYTECODE=TRUE
ENV PATH="/opt/program:${PATH}"
ENV PYTHONPATH /model_contents

# Set up the program in the image
COPY bandit/ /opt/program/
WORKDIR /opt/program/

# create directories for storing model and vectorizer
RUN mkdir model && mkdir vectorizer

# Give permissions to run scripts
RUN chmod +x /opt/program/serve && chmod +x /opt/program/train

requirements.txt here: requirements.txt 在这里:

sagemaker==2.25.1
typing-extensions==3.7.4.3
numpy==1.20.1
boto3==1.17.12
awscli==1.19.12
python-dotenv==0.15.0
flask==1.1.2
scikit-learn==1.0.0
pandas==1.3.5
vowpalwabbit==8.11.0

Full traceback here:完整的追溯在这里:

Running setup.py install for numpy: started

    Running setup.py install for numpy: finished with status 'error'

    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-cd653krx/numpy/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-q3eo46tw-record/install-record.txt --single-version-externally-managed --compile:

    Running from numpy source directory.

    Note: if you need reliable uninstall behavior, then install

    with pip instead of using `setup.py install`:

      - `pip install .`       (from a git repo or downloaded source

                               release)

      - `pip install numpy`   (last NumPy release on PyPi)

    Cythonizing sources

    Processing numpy/random/_bounded_integers.pxd.in

    Processing numpy/random/_bounded_integers.pyx.in

    Traceback (most recent call last):

      File "/tmp/pip-build-cd653krx/numpy/tools/cythonize.py", line 53, in process_pyx

        import Cython

    ModuleNotFoundError: No module named 'Cython'

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):

      File "/tmp/pip-build-cd653krx/numpy/tools/cythonize.py", line 234, in <module>

        main()

      File "/tmp/pip-build-cd653krx/numpy/tools/cythonize.py", line 230, in main

        find_process_files(root_dir)

      File "/tmp/pip-build-cd653krx/numpy/tools/cythonize.py", line 221, in find_process_files

        process(root_dir, fromfile, tofile, function, hash_db)

      File "/tmp/pip-build-cd653krx/numpy/tools/cythonize.py", line 187, in process

        processor_function(fromfile, tofile)

      File "/tmp/pip-build-cd653krx/numpy/tools/cythonize.py", line 90, in process_tempita_pyx

        process_pyx(pyxfile, tofile)

      File "/tmp/pip-build-cd653krx/numpy/tools/cythonize.py", line 60, in process_pyx

        raise OSError(msg) from e

    OSError: Cython needs to be installed in Python as a module

    Traceback (most recent call last):

      File "<string>", line 1, in <module>

      File "/tmp/pip-build-cd653krx/numpy/setup.py", line 450, in <module>

        setup_package()

      File "/tmp/pip-build-cd653krx/numpy/setup.py", line 432, in setup_package

        generate_cython()

      File "/tmp/pip-build-cd653krx/numpy/setup.py", line 237, in generate_cython

        raise RuntimeError("Running cythonize failed!")

    RuntimeError: Running cythonize failed!

There are 2 ways to get around the issue -有两种方法可以解决这个问题 -

  1. Add the numpy version you need as part of your requirements.txt ( preferred way so that you can manage your dependencies and version better)添加您需要的numpy版本作为您的 requirements.txt 的一部分(首选方式,以便您可以更好地管理您的依赖项和版本)

  2. Install in dependency in the Dockerfile directly.直接在 Dockerfile 中安装依赖。

I work at AWS and my opinions are my own - Thanks,Raghu我在 AWS 工作,我的意见是我自己的 - 谢谢,Raghu

Solved the issue.解决了这个问题。 The numpy version was causing conflicts with the rest of the packages so downgraded which solved the issue. numpy 版本导致与 rest 软件包发生冲突,因此降级解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 CLI 在 AWS 中构建一个 docker 图像 - building a docker image in AWS with CLI 构建 docker 文件时,Tensorflow 在 AWS python3.8 图像上安装失败 - Tensorflow insatllation is failing on AWS python3.8 image when building the docker file AWS SAM CLI 抛出错误:构建 docker 图像时出错 - AWS SAM CLI throws error: Error building docker image Cloud Build Docker 未构建 - Cloud Build Docker not building 与 Firestore 一起使用时在 buildSrc 中出现 kotlin 依赖问题 - Getting kotlin dependency issue in buildSrc when used with Firestore 将 docker 图片推送到 GCR 时授权失败 - Failed to authorize when pushing docker image to GCR 在 Ubuntu 上构建 docker 图像:来自守护程序的错误响应:无效的过滤器“参考” - Building a docker image on Ubuntu: Error response from daemon: Invalid filter 'reference' Google Cloud Run - Docker building container building but not accessible - Google Cloud Run - Docker building container building but not accessible Terraform - GCP 上的循环依赖问题 - Terraform - Cyclic dependency issue on GCP ClassNotFoundException - 在构建图像时使用 BitBucket 管道中的 jib-maven-plugin 将其推送到 GCR - ClassNotFoundException - when building the image & push it to GCR using jib-maven-plugin in BitBucket pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM