安装 OpenCV 失败,因为它找不到“skbuild”

Posted

技术标签:

【中文标题】安装 OpenCV 失败,因为它找不到“skbuild”【英文标题】:Installing OpenCV fails because it cannot find "skbuild" 【发布时间】:2020-12-06 10:46:30 【问题描述】:

我有一个需要在其中安装 openCV 的 docker 映像,从昨天开始它开始失败,因为它找不到“skbuild”模块:

Step 12/24 : RUN pip install opencv-python opencv-contrib-python
 ---> Running in a0f746a23aed
Collecting opencv-python
  Downloading https://files.pythonhosted.org/packages/77/f5/49f034f8d109efcf9b7e98fbc051878b83b2f02a1c73f92bbd37f317288e/opencv-python-4.4.0.42.tar.gz (88.9MB)
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-cciracwm/opencv-python/setup.py", line 9, in <module>
        import skbuild
    ModuleNotFoundError: No module named 'skbuild'

在主机上我也找不到该模块,pip search 要么不返回任何内容,要么返回服务器错误:

sudo pip3 search skbuild
WARNING: The directory '/home/ali/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
ERROR: Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/base_command.py", line 216, in _main
    status = self.run(options, args)
  File "/usr/local/lib/python3.6/dist-packages/pip/_internal/commands/search.py", line 60, in run
    pypi_hits = self.search(query, options)
  File "/usr/local/lib/python3.6/dist-packages/pip/_internal/commands/search.py", line 80, in search
    hits = pypi.search('name': query, 'summary': query, 'or')
  File "/usr/lib/python3.6/xmlrpc/client.py", line 1112, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python3.6/xmlrpc/client.py", line 1452, in __request
    verbose=self.__verbose
  File "/usr/local/lib/python3.6/dist-packages/pip/_internal/network/xmlrpc.py", line 45, in request
    return self.parse_response(response.raw)
  File "/usr/lib/python3.6/xmlrpc/client.py", line 1342, in parse_response
    return u.close()
  File "/usr/lib/python3.6/xmlrpc/client.py", line 656, in close
    raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault -32403: 'server error; service unavailable'>

这是因为他们的服务器有问题还是和我的pip有关?

更新

我在不同的 python 和 pip 版本、python 版本 3.6 和 3.7 以及 pip 版本 19.12 和 20.2.2 和 9.0.1(内部图像)上进行了尝试。

更新 2

我在安装 opencv 之前添加了pip install scikit-build,但我收到了另一个与 cmake 相关的错误:

Step 12/25 : RUN pip install scikit-build
 ---> Running in afe0c5c0fca0
Collecting scikit-build
  Downloading https://files.pythonhosted.org/packages/78/c9/7c2c7397ea64e36ebb292446896edcdecbb8c1aa6b9a1a32f6f67984c3df/scikit_build-0.11.1-py2.py3-none-any.whl (72kB)
Collecting packaging (from scikit-build)
  Downloading https://files.pythonhosted.org/packages/46/19/c5ab91b1b05cfe63cccd5cfc971db9214c6dd6ced54e33c30d5af1d2bc43/packaging-20.4-py2.py3-none-any.whl
Requirement already satisfied: wheel>=0.29.0 in /usr/lib/python3/dist-packages (from scikit-build)
Collecting distro (from scikit-build)
  Downloading https://files.pythonhosted.org/packages/25/b7/b3c4270a11414cb22c6352ebc7a83aaa3712043be29daa05018fd5a5c956/distro-1.5.0-py2.py3-none-any.whl
Requirement already satisfied: setuptools>=28.0.0; python_version >= "3" in /usr/lib/python3/dist-packages (from scikit-build)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from packaging->scikit-build)
Collecting pyparsing>=2.0.2 (from packaging->scikit-build)
  Downloading https://files.pythonhosted.org/packages/8a/bb/488841f56197b13700afd5658fc279a2025a39e22449b7cf29864669b15d/pyparsing-2.4.7-py2.py3-none-any.whl (67kB)
Installing collected packages: pyparsing, packaging, distro, scikit-build
Successfully installed distro-1.5.0 packaging-20.4 pyparsing-2.4.7 scikit-build-0.11.1
Removing intermediate container afe0c5c0fca0
 ---> 533658ddf26d
Step 13/25 : RUN pip install opencv-python opencv-contrib-python
 ---> Running in 0f2c03bc042a
Collecting opencv-python
  Downloading https://files.pythonhosted.org/packages/77/f5/49f034f8d109efcf9b7e98fbc051878b83b2f02a1c73f92bbd37f317288e/opencv-python-4.4.0.42.tar.gz (88.9MB)
Collecting opencv-contrib-python
  Downloading https://files.pythonhosted.org/packages/48/98/05bd8e00c71b66c4e7847cc051cac404191d904df58b51a7dcc3767ff747/opencv_contrib_python-4.2.0.34-cp37-cp37m-manylinux1_x86_64.whl (34.2MB)
Collecting numpy>=1.14.5 (from opencv-python)
  Downloading https://files.pythonhosted.org/packages/3d/d1/90cd7e0b27ee86d77f5386d38b74520486100286d50772377791b6ef22ff/numpy-1.19.1-cp37-cp37m-manylinux1_x86_64.whl (13.4MB)
Building wheels for collected packages: opencv-python
  Running setup.py bdist_wheel for opencv-python: started
  Running setup.py bdist_wheel for opencv-python: finished with status 'error'
  Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-w49xv99a/opencv-python/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/tmpycj03zlwpip-wheel- --python-tag cp37:
  /usr/lib/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: 'long_description_content_type'
    warnings.warn(msg)
  Traceback (most recent call last):
    File "/usr/local/lib/python3.7/dist-packages/skbuild/setuptools_wrap.py", line 560, in setup
      cmkr = cmaker.CMaker(cmake_executable)
    File "/usr/local/lib/python3.7/dist-packages/skbuild/cmaker.py", line 95, in __init__
      self.cmake_version = get_cmake_version(self.cmake_executable)
    File "/usr/local/lib/python3.7/dist-packages/skbuild/cmaker.py", line 82, in get_cmake_version
      "Problem with the CMake installation, aborting build. CMake executable is %s" % cmake_executable)
  
  Problem with the CMake installation, aborting build. CMake executable is cmake
  
  ----------------------------------------
  Failed building wheel for opencv-python
  Running setup.py clean for opencv-python
Failed to build opencv-python
Installing collected packages: numpy, opencv-python, opencv-contrib-python
  Found existing installation: numpy 1.13.3
    Not uninstalling numpy at /usr/lib/python3/dist-packages, outside environment /usr
  Running setup.py install for opencv-python: started
    Running setup.py install for opencv-python: finished with status 'error'
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-w49xv99a/opencv-python/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-maky1uyw-record/install-record.txt --single-version-externally-managed --compile:
    /usr/lib/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: 'long_description_content_type'
      warnings.warn(msg)
    Traceback (most recent call last):
      File "/usr/local/lib/python3.7/dist-packages/skbuild/setuptools_wrap.py", line 560, in setup
        cmkr = cmaker.CMaker(cmake_executable)
      File "/usr/local/lib/python3.7/dist-packages/skbuild/cmaker.py", line 95, in __init__
        self.cmake_version = get_cmake_version(self.cmake_executable)
      File "/usr/local/lib/python3.7/dist-packages/skbuild/cmaker.py", line 82, in get_cmake_version
        "Problem with the CMake installation, aborting build. CMake executable is %s" % cmake_executable)
    
    Problem with the CMake installation, aborting build. CMake executable is cmake

【问题讨论】:

我遇到了类似的问题。当我pip install opencv-python 时,它会出现类似的错误消息Problem with the CMake installation, aborting build. CMake executable is cmake。关于到目前为止的答案,这是在更新 pip(到 20.2.2)、安装 scikit-build 和安装 cmake 之后。 (并更新了 setuptools)。 如果您不需要全新的功能,请考虑安装稍旧的版本。 github.com/openvinotoolkit/dlstreamer_gst/issues/… Google 员工,请像往常一样尝试sudo pip3 install --upgrade pip,然后尝试pip3(而不是pip 等效项)。 【参考方案1】:

如果您阅读opencv-pythonpackage FAQ in PyPI,它清楚地为这个特定问题提供了答案:您必须运行pip install --upgrade pip。之后用pip -V检查pip的版本。

这是因为您的pip 太旧,无法理解新的manylinux2014 包格式并尝试从源代码编译。这也将失败,因为pip 太旧,无法理解如何使用pyproject.toml 安装构建依赖项,例如scikit-build

我发现的另一个问题是您同时安装了opencv-pythonopencv-contrib-python。你不应该这样做。它也在包的 PyPI 页面中进行了解释。很可能您应该只使用 opencv-contrib-python-headless 包,因为您使用的是 Docker,而且我假设您不使用 OpenCV 的 GUI 功能。

【讨论】:

我没有明确提到这一点,但我已经在主机和图像内部更新了我的 pip,并且 20.2.2 版本来自那里并且没有工作。我们已经安装了opencv-pythonopencv-contrib-python 很长时间了,我们以前从来没有遇到过问题,但是为什么我们需要这两个我不知道,因为我的同事是这个 repo 的所有者,正在度假。 主机 pip 与 Docker 无关。在运行安装之前,您是否确认 Docker 映像中的版本为 => 19.3?您不需要两者,因为第二个总是会覆盖第一个并且您最终会遇到不一致的环境。 我知道主机 pip 与 docker 无关,但正如我在问题中提到的,我的主机以及主机和容器内部也有这个问题,我确认管道版本是 20.2.2。谢谢你的提示,我会告诉我的同事。 Docker 环境确实有些奇怪,因为另一个包使用旧的预构建 manylinux1 包和其他下载源分发(来自您的输出):opencv-python-4.4.0.42 .tar.gz (88.9MB) opencv_contrib_python-4.2.0.34-cp37-cp37m-manylinux1_x86_64.whl【参考方案2】:

只需更新 pip 即可使用

python -m pip install --upgrade pip

【讨论】:

【参考方案3】:

skbuild 用于 Scikit-build。

使用 pip 安装:

windows:pip install scikit-build

安装成功后:

pip install cmake

【讨论】:

没用,我更新了我的问题,你可以看到结果了。【参考方案4】:

只需更新点子。 如果你使用python3,那么:

pip3 install --upgrade pip
pip3 install opencv-python

【讨论】:

【参考方案5】:

因为我安装了python3,所以我不得不使用

python3 -m pip install --upgrade pip

【讨论】:

【参考方案6】:

2021 年 5 月 11 日:在新的 ubuntu18 virtualbox 映像上遇到了同样的问题。这对我有用

sudo -H pip3 install --upgrade pip

pip3 install opencv-python

【讨论】:

【参考方案7】:

在执行时我也遇到了错误

python3.7 -m pip install --user opencv-python 以使catkin_make -j8 在 ROS 项目中再次工作。因此,不需要 Docker 来获取错误。

首先是细节:

Collecting opencv-python
  Cache entry deserialization failed, entry ignored
  Downloading https://files.pythonhosted.org/packages/30/46/821920986c7ce5bae5518c1d490e520a9ab4cef51e3e54e35094dadf0d68/opencv-python-4.4.0.46.tar.gz (88.9MB)
    100% |████████████████████████████████| 88.9MB 17kB/s 
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-8jky5692/opencv-python/setup.py", line 9, in <module>
        import skbuild
    ModuleNotFoundError: No module named 'skbuild'
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-8jky5692/opencv-python/

只是记录我为解决它所做的工作:

python -m pip install --user opencv-python 给我/usr/bin/python: No module named pip sudo apt install python-pip(除了现有的用于 pip3 的 sudo apt install python3-pip 安装) python -m pip -V 现在给我pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7) pip -V 给了我pip 20.3.3 from /home/MYUSERNAME/.local/lib/python3.6/site-packages/pip (python 3.6)(因为 apt-get 安装了标准的 3.6,独立于现有的 python 版本) sudo apt-get update &amp;&amp; sudo apt-get install cmake libopenmpi-dev python3.7-dev zlib1g-dev(不确定是否需要此步骤) pip install opencv-python 工作中 catkin_make -j8 在 Python 基础环境 WORKING 中我的 catkin 工作区中

更新 2

中提到的 cmake 错误的其他提示

这个 cmake 错误可能是由于catkin_make 安装期间或之后的工作空间损坏:

当我在 Python 虚拟环境中执行 catkin_make 命令时,我遇到了类似的 cmake 错误。当我改回基本环境(使用deactivate)时,catkin_make 运行通过。这可能是由于虚拟环境中的依赖性问题,也可能是因为您使用某些内部脚本使用的标准python -m 时使用的版本,请参阅上面的要点之一。我不得不将 python2.7 分配给python -m pip -V pip 版本,可能是因为 ROS Gazebo 需要 2.7。 最有希望的(如果这是一个 catkin 问题):只需移除 catkin 并重新安装,请参阅 Error 2 Invoking "make -j4 -l4" failed。 或许也可以看看Invoking "cmake" failed。

【讨论】:

【参考方案8】:

我遇到了类似的问题,最终奏效的是从 python:3-alpine 更改为 python:3.8-slim 并安装 python 和 openCV,类似于此处所选答案中所做的:Minimal SciPy Dockerfile

【讨论】:

【参考方案9】:

使用 python3 你需要使用 pip3

【讨论】:

以上是关于安装 OpenCV 失败,因为它找不到“skbuild”的主要内容,如果未能解决你的问题,请参考以下文章

Keycloak 失败,因为它找不到我的主题或带有 NullPointer 异常的默认主题

pip 无法安装软件包,因为它找不到 swig2.0 二进制文件

无法在 Mac 上安装 Ruby gem libxslt-ruby,因为它找不到 libxml2

pkg-config 找不到 opencv

离子找不到平台

为啥我不能从 VM 分离磁盘?它说这是因为它找不到存储。但是我已经删除了存储