opencv安装的docker Build中出错“找不到OpenCVContriblePythonHeadless==4.5.3.56的匹配发行版”

2024-04-19 00:55:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我是新来的码头工人。我正在尝试为使用flask的ml模型创建docker映像。 我已经正确设置了虚拟环境,并在其中下载了所有必需的软件包。 使用opencv python时会出现错误,因此我将其删除并安装了opencv contrib python headless,但根本不起作用。此外,它还显示了一些关于未找到版本1.19.3的numpy错误,我试图通过在requirements.txt中更改numpy的版本来解决该错误,该版本也不起作用。 以下是构建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

dockerfile

from alpine:latest
COPY . /app
WORKDIR /app
RUN set -xe \
    && 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_landmarks.dat文件。 导入app.py正在制作:

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

除了opencv之外,所有软件包的下载和安装都运行良好

请帮忙


Tags: pipandbuildnumpycmakenoneversionstatus