ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly

ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly

我试图在 docker 上的 jetson nano 上安装 OpenCV4。它有 4.4 秒的喷气背包 os。 docker 已成功创建并且 Tensorflow 是 运行 但是在使用 pip 安装 OpenCV 时显示 CMake 错误。

root@5abf405fb92d:~# pip3 install opencv-python
Collecting opencv-python
  Downloading opencv-python-4.4.0.42.tar.gz (88.9 MB)
     |████████████████████████████████| 88.9 MB 2.5 kB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: numpy>=1.13.3 in /usr/local/lib/python3.6/dist-packages (from opencv-python) (1.18.4)
Building wheels for collected packages: opencv-python
  Building wheel for opencv-python (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /usr/local/lib/python3.6/dist-packages/pip/_vendor/pep517/_in_process.py build_wheel /tmp/tmpqpzwrofy
       cwd: /tmp/pip-install-93nxibky/opencv-python
  Complete output (9 lines):
    File "/tmp/pip-build-env-o_hualnr/overlay/lib/python3.6/site-packages/skbuild/setuptools_wrap.py", line 560, in setup
      cmkr = cmaker.CMaker(cmake_executable)
    File "/tmp/pip-build-env-o_hualnr/overlay/lib/python3.6/site-packages/skbuild/cmaker.py", line 95, in __init__
      self.cmake_version = get_cmake_version(self.cmake_executable)
    File "/tmp/pip-build-env-o_hualnr/overlay/lib/python3.6/site-packages/skbuild/cmaker.py", line 82, in get_cmake_version
      "Problem with the CMake installation, aborting build. CMake executable is %s" % cmake_executable)
  Traceback (most recent call last):
  
  Problem with the CMake installation, aborting build. CMake executable is cmake
  ----------------------------------------
  ERROR: Failed building wheel for opencv-python
Failed to build opencv-python
ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly

我遇到了同样的问题,我这样做了,

pip install --upgrade pip setuptools wheel

然后再安装opencv,

pip install opencv-python

这对我有用

是的..终于找到了解决方法。 按照此 https://github.com/mdegans/nano_build_opencv 并从源代码构建并最终安装。

PS: 构建可能需要一点时间,对我来说花了 10 个小时 :P.

快乐Image-Processing..

如果在

之后
pip install --upgrade pip setuptools wheel

你仍然有同样的错误,

您可以尝试指定老版本的OpenCV安装

例如

pip3 install opencv-python==3.4.13.47

我遇到了类似的问题,为我解决的不是使用 python:3-alpine,而是 python:3.8-slim。例如:

FROM python:3.8-slim
WORKDIR /usr/src/app

RUN apt update
RUN apt -y install build-essential libwrap0-dev libssl-dev libc-ares-dev uuid-dev xsltproc
RUN apt-get update -qq \
    && apt-get install --no-install-recommends --yes \
        build-essential \
        gcc \
        python3-dev \
        mosquitto \
        mosquitto-clients


RUN pip3 install --upgrade pip setuptools wheel

RUN python3 -m pip install --no-cache-dir \
      numpy scipy matplotlib scikit-build opencv-contrib-python-headless \
      influxdb paho-mqtt configparser Pillow \
      qrcode

终于对我有用了。

请检查您的 python 规格:


  - opencv -> python[
version='
>=2.7,<2.8.0a0
>=3.5,<3.6.0a0
>=3.6,<3.7.0a0
>=3.7,<3.8.0a0']

我通过在我的 MacBook 中从头开始重新安装 python3 来处理它:

brew reinstall python@3.9

我还实验性地重新安装了 numpy 和 matplotlib 包。

pip3 install numpy
pip3 install matplotlib 
pip3 install opencv-contrib-python

版本:

macOS 莫哈韦沙漠 10.14.5
Python3.9.7
OpenCV 4.5.3

OpenCV 的版本是 4.5.3 by this way:

import cv2 
print(cv2.__version__)

但是通过“pip list”,它显示“opencv-contrib-python 3.4.9.31”。

如果您尝试在 raspberrypi 3B 中安装 opencv,请使用以下步骤:

  1. sudo raspi-config
  2. 高级 -- 扩展文件系统
  3. 重启你的 pi

打开您的 raspi 终端并执行以下操作:

  1. 使用命令:sudo apt-get update
  2. 使用命令:sudo apt-get升级
  3. 检查您的 python 版本并将其升级到最新版本
  4. 安装 pip 并升级 pip
  5. 使用命令:mkdir 项目
  6. 使用命令:cd project
  7. 创建虚拟环境
  8. 激活虚拟环境
  9. 安装依赖,可以从https://singleboardbytes.com/647/install-opencv-raspberry-pi-4.htm
  10. 获取依赖
  11. 如果安装 libdhf5-dev 时出错
  12. 使用命令:sudo apt-get 安装 python3-h5py 并重新安装 libdhf5-dev
  13. 使用命令:pip install scikit-build
  14. 使用命令:pip install cython
  15. 在安装opencv之前,确保你在虚拟环境中或者 激活环境
  16. 使用命令:pip install --no-cache-dir opencv-contrib-python==4.5.3.56
  17. 记得使用提到的版本...

谢谢...

我遇到过类似情况
我有错误

Failed to build opencv-python ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly WARNING: You are using pip version 19.2.3, however version 22.0.4 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.

我 运行 在具有管理员权限的命令提示符下
python -m pip 安装 --upgrade pip
现在“pip install opencv-python”有效