ошибка в сборке docker для установки opencv «Не найдено соответствующего дистрибутива для opencv-contrib-python-headless==4.5.3.56»

#python #linux #docker #machine-learning #flask

Вопрос:

Я новичок в докере. Я пытаюсь создать образ докера для своей модели ml, в которой используется колба. Я правильно настроил виртуальную среду и загрузил в нее все необходимые пакеты. Использование opencv-python приводило к ошибке, поэтому я удалил его, установив opencv-contrib-python-безголовый, но он вообще не работает. Также он показывает некоторую ошибку numpy относительно не найденной версии 1.19.3, которую я попытался устранить, изменив версию numpy в requirements.txt что тоже не сработало. Вот ошибка при создании изображения flaskapp

  > [8/8] RUN pip install -r requirements.txt:
#13 1.955 Collecting click==8.0.1
#13 2.817   Downloading click-8.0.1-py3-none-any.whl (97 kB)
#13 4.051 Collecting cmake==3.21.1.post1
#13 4.263   Downloading cmake-3.21.1.post1.tar.gz (30 kB)
#13 4.524   Installing build dependencies: started
#13 15.26   Installing build dependencies: finished with status 'done'
#13 15.27   Getting requirements to build wheel: started
#13 15.65   Getting requirements to build wheel: finished with status 'done'
#13 15.66     Preparing wheel metadata: started
#13 16.02     Preparing wheel metadata: finished with status 'done'
#13 16.27 Collecting dlib==19.22.0
#13 16.40   Downloading dlib-19.22.0.tar.gz (7.4 MB)
#13 23.27 Collecting Flask==2.0.1
#13 23.40   Downloading Flask-2.0.1-py3-none-any.whl (94 kB)
#13 23.71 Collecting imageio==2.9.0
#13 23.85   Downloading imageio-2.9.0-py3-none-any.whl (3.3 MB)
#13 25.20 Collecting itsdangerous==2.0.1
#13 25.33   Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
#13 25.68 Collecting Jinja2==3.0.1
#13 25.81   Downloading Jinja2-3.0.1-py3-none-any.whl (133 kB)
#13 26.21 Collecting MarkupSafe==2.0.1
#13 26.34   Downloading MarkupSafe-2.0.1.tar.gz (18 kB)
#13 27.52 Collecting numpy==1.21.1
#13 27.64   Downloading numpy-1.21.1.zip (10.3 MB)
#13 31.54   Installing build dependencies: started
#13 40.30   Installing build dependencies: finished with status 'done'
#13 40.31   Getting requirements to build wheel: started
#13 40.91   Getting requirements to build wheel: finished with status 'done'
#13 40.91     Preparing wheel metadata: started
#13 41.43     Preparing wheel metadata: finished with status 'done'
#13 42.24 Collecting opencv-contrib-python-headless==4.5.3.56
#13 42.46   Downloading opencv-contrib-python-headless-4.5.3.56.tar.gz (150.2 MB)
#13 94.80   Installing build dependencies: started
#13 217.0   Installing build dependencies: still running...
#13 294.0   Installing build dependencies: still running...
#13 366.7   Installing build dependencies: still running...
#13 398.0   Installing build dependencies: finished with status 'error'
#13 398.0   ERROR: Command errored out with exit status 1:
#13 398.0    command: /usr/bin/python3 /tmp/pip-standalone-pip-dozxy1os/__env_pip__.zip/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-53av5svj/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel scikit-build cmake pip 'numpy==1.13.3; python_version=='"'"'3.6'"'"' and platform_machine != '"'"'aarch64'"'"' and platform_machine != '"'"'arm64'"'"'' 'numpy==1.19.3; python_version>='"'"'3.6'"'"' and sys_platform == '"'"'linux'"'"' and platform_machine == '"'"'aarch64'"'"'' 'numpy==1.21.0; python_version>='"'"'3.6'"'"' and sys_platform == '"'"'darwin'"'"' and platform_machine == '"'"'arm64'"'"'' 'numpy==1.14.5; python_version=='"'"'3.7'"'"' and platform_machine != '"'"'aarch64'"'"' and platform_machine != '"'"'arm64'"'"'' 'numpy==1.17.3; python_version=='"'"'3.8'"'"' and platform_machine != '"'"'aarch64'"'"' and platform_machine != '"'"'arm64'"'"'' 'numpy==1.19.3; python_version>='"'"'3.9'"'"' and platform_machine != '"'"'aarch64'"'"' and platform_machine != '"'"'arm64'"'"''
#13 398.0        cwd: None
#13 398.0   Complete output (63 lines):
#13 398.0   Ignoring numpy: markers 'python_version == "3.6" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment
#13 398.0   Ignoring numpy: markers 'python_version >= "3.6" and sys_platform == "linux" and platform_machine == "aarch64"' don't match your environment
#13 398.0   Ignoring numpy: markers 'python_version >= "3.6" and sys_platform == "darwin" and platform_machine == "arm64"' don't match your environment
#13 398.0   Ignoring numpy: markers 'python_version == "3.7" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment
#13 398.0   Ignoring numpy: markers 'python_version == "3.8" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment
#13 398.0   Collecting setuptools
#13 398.0     Using cached setuptools-57.4.0-py3-none-any.whl (819 kB)
#13 398.0   Collecting wheel
#13 398.0     Using cached wheel-0.37.0-py2.py3-none-any.whl (35 kB)
#13 398.0   Collecting scikit-build
#13 398.0     Using cached scikit_build-0.12.0-py2.py3-none-any.whl (73 kB)
#13 398.0   Collecting cmake
#13 398.0     Using cached cmake-3.21.1.post1.tar.gz (30 kB)
#13 398.0     Installing build dependencies: started
#13 398.0     Installing build dependencies: finished with status 'done'
#13 398.0     Getting requirements to build wheel: started
#13 398.0     Getting requirements to build wheel: finished with status 'done'
#13 398.0       Preparing wheel metadata: started
#13 398.0       Preparing wheel metadata: finished with status 'done'
#13 398.0   Collecting pip
#13 398.0     Using cached pip-21.2.4-py3-none-any.whl (1.6 MB)
#13 398.0   Collecting numpy==1.19.3
#13 398.0     Downloading numpy-1.19.3.zip (7.3 MB)
#13 398.0     Installing build dependencies: started
#13 398.0     Installing build dependencies: finished with status 'done'
#13 398.0     Getting requirements to build wheel: started
#13 398.0     Getting requirements to build wheel: finished with status 'done'
#13 398.0       Preparing wheel metadata: started
#13 398.0       Preparing wheel metadata: finished with status 'done'
#13 398.0   Collecting packaging
#13 398.0     Using cached packaging-21.0-py3-none-any.whl (40 kB)
#13 398.0   Collecting distro
#13 398.0     Using cached distro-1.6.0-py2.py3-none-any.whl (19 kB)
#13 398.0   Collecting pyparsing>=2.0.2
#13 398.0     Using cached pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)
#13 398.0   Building wheels for collected packages: numpy, cmake
#13 398.0     Building wheel for numpy (PEP 517): started
#13 398.0     Building wheel for numpy (PEP 517): still running...
#13 398.0     Building wheel for numpy (PEP 517): still running...
#13 398.0     Building wheel for numpy (PEP 517): still running...
#13 398.0     Building wheel for numpy (PEP 517): finished with status 'done'
#13 398.0     Created wheel for numpy: filename=numpy-1.19.3-cp39-cp39-linux_x86_64.whl size=18470016 sha256=b4758079465884a8fb96dc6ecb8a82386f013d0199e9100ba0ddcad075354fb2
#13 398.0     Stored in directory: /root/.cache/pip/wheels/4d/97/39/76706423acf6715e3a0a125c08fb7e33fcbc5bbd0386893b83
#13 398.0     Building wheel for cmake (PEP 517): started
#13 398.0     Building wheel for cmake (PEP 517): finished with status 'error'
#13 398.0     ERROR: Command errored out with exit status 1:
#13 398.0      command: /usr/bin/python3 /tmp/tmpdifl4p0i_in_process.py build_wheel /tmp/tmpwgdizvck
#13 398.0          cwd: /tmp/pip-install-g5m46fmj/cmake_668758a82f7d475c834b73646d7bce4b
#13 398.0     Complete output (9 lines):
#13 398.0       File "/tmp/pip-build-env-ep2qufm3/overlay/lib/python3.9/site-packages/skbuild/setuptools_wrap.py", line 564, in setup
#13 398.0         cmkr = cmaker.CMaker(cmake_executable)
#13 398.0       File "/tmp/pip-build-env-ep2qufm3/overlay/lib/python3.9/site-packages/skbuild/cmaker.py", line 95, in __init__
#13 398.0         self.cmake_version = get_cmake_version(self.cmake_executable)
#13 398.0       File "/tmp/pip-build-env-ep2qufm3/overlay/lib/python3.9/site-packages/skbuild/cmaker.py", line 81, in get_cmake_version
#13 398.0         raise SKBuildError(
#13 398.0     Traceback (most recent call last):
#13 398.0
#13 398.0     Problem with the CMake installation, aborting build. CMake executable is cmake
#13 398.0     ----------------------------------------
#13 398.0     ERROR: Failed building wheel for cmake
#13 398.0   Successfully built numpy
#13 398.0   Failed to build cmake
#13 398.0   ERROR: Could not build wheels for cmake which use PEP 517 and cannot be installed directly
#13 398.0   ----------------------------------------
#13 398.0 WARNING: Discarding https://files.pythonhosted.org/packages/98/6e/28b059672cdc0c1dac56369e8f2de1b07383fcc4ce1f390a3be65cc124e3/opencv-contrib-python-headless-4.5.3.56.tar.gz#sha256=c99c60dac84149617e030c40da172a6a7f5f70d9b8a7e8ee75adc6208cd9e0e4 (from https://pypi.org/simple/opencv-contrib-python-headless/) (requires-python:>=3.6). Command errored out with exit status 1: /usr/bin/python3 /tmp/pip-standalone-pip-dozxy1os/__env_pip__.zip/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-53av5svj/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel scikit-build cmake pip 'numpy==1.13.3; python_version=='"'"'3.6'"'"' and platform_machine != '"'"'aarch64'"'"' and platform_machine != '"'"'arm64'"'"'' 'numpy==1.19.3; python_version>='"'"'3.6'"'"' and sys_platform == '"'"'linux'"'"' and platform_machine == '"'"'aarch64'"'"'' 'numpy==1.21.0; python_version>='"'"'3.6'"'"' and sys_platform == '"'"'darwin'"'"' and platform_machine == '"'"'arm64'"'"'' 'numpy==1.14.5; python_version=='"'"'3.7'"'"' and platform_machine != '"'"'aarch64'"'"' and platform_machine != '"'"'arm64'"'"'' 'numpy==1.17.3; python_version=='"'"'3.8'"'"' and platform_machine != '"'"'aarch64'"'"' and platform_machine != '"'"'arm64'"'"'' 'numpy==1.19.3; python_version>='"'"'3.9'"'"' and platform_machine != '"'"'aarch64'"'"' and platform_machine != '"'"'arm64'"'"'' Check the logs for full command output.
#13 398.0 ERROR: Could not find a version that satisfies the requirement opencv-contrib-python-headless==4.5.3.56 (from versions: 3.4.11.45, 3.4.13.47, 3.4.14.51, 3.4.15.55, 4.4.0.46, 4.5.1.48, 4.5.2.52, 4.5.3.56)
#13 398.0 ERROR: No matching distribution found for opencv-contrib-python-headless==4.5.3.56
------
executor failed running [/bin/sh -c pip install -r requirements.txt]: exit code: 1
 

requirements.txt выполняется сборка с использованием команды pip freeze
Requirements.txt файл

 click==8.0.1
cmake==3.21.1.post1
dlib==19.22.0
Flask==2.0.1
imageio==2.9.0
itsdangerous==2.0.1
Jinja2==3.0.1
MarkupSafe==2.0.1
numpy==1.21.1
opencv-contrib-python-headless==4.5.3.56
Pillow==8.3.1
Werkzeug==2.0.1
 

докерфайл

 from alpine:latest
COPY . /app
WORKDIR /app
RUN set -xe 
    amp;amp; apk add --update py3-pip
RUN apk update
RUN apk add make automake gcc g   subversion python3-dev
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
 

проект также содержит метки shape_predictor_68_face_land.файл dat.
Импорт app.py делает :

 from flask import Flask, render_template, request, jsonify
import cv2
import numpy as np
import dlib
import imageio
 

Все загрузки и установки пакетов работают хорошо, за исключением opencv.

Пожалуйста, помогите.

Комментарии:

1. если вы просто активируете venv и попытаетесь установить пакет opencv pip, что произойдет? Я почти уверен, что это не удастся. Пожалуйста, поделитесь этими подробностями, и я вижу, что вы используете alpine, это не сработает, потому что opencv-это двоичный дистрибутив, а alpine использует c.

2. Просто измените первую строку dockerfiles на эту: с python:3.8

3. @RajVerma Большое тебе спасибо. Я искренне ценю вашу помощь. Изменение alpine:последняя версия на python:3.9 сработало для меня, а также установка pip opencv-python уже удовлетворял требованиям в virtual env. Еще раз спасибо Вам.