python - 错误:无法为使用PEP 517且无法直接安装的opencv-python构建轮子(在PATH中找不到cl)

标签 python c++ opencv cmake

我试图在Visual Studio中安装opencv-python(已安装Visual Studio 2019),但不断出现此错误。我已经尝试过有关此PEP517错误的大多数以前发布的方法,但是我仍然遇到错误。如果我只是一个初学者,请感谢有人可以在这里帮助我。在此先感谢。
下面是错误代码:

$ pip install opencv-python
Collecting opencv-python
  Using cached opencv-python-4.4.0.44.tar.gz (88.9 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: numpy>=1.17.3 in c:\python\lib\site-packages (from opencv-python) (1.19.2)
Building wheels for collected packages: opencv-python
  Building wheel for opencv-python (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\python\python.exe' 'c:\python\lib\site-packages\pip\_vendor\pep517\_in_process.py' build_wheel 'C:\Users\Austen\AppData\Local\Temp\tmp6zo4yrsx'
       cwd: C:\Users\Austen\AppData\Local\Temp\pip-install-tcb_5anh\opencv-python
  Complete output (153 lines):
  Not searching for unused variables given on the command line.
  CMake Error: CMake was unable to find a build program corresponding to "Ninja".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
  -- Configuring incomplete, errors occurred!
  See also "C:/Users/Austen/AppData/Local/Temp/pip-install-tcb_5anh/opencv-python/_cmake_test_compile/build/CMakeFiles/CMakeOutput.log".
  Not searching for unused variables given on the command line.
  CMake Error at CMakeLists.txt:2 (PROJECT):
    Generator

      Visual Studio 15 2017 Win64

    could not find any instance of Visual Studio.


  -- Configuring incomplete, errors occurred!
  See also "C:/Users/Austen/AppData/Local/Temp/pip-install-tcb_5anh/opencv-python/_cmake_test_compile/build/CMakeFiles/CMakeOutput.log".
  Not searching for unused variables given on the command line.
  -- The C compiler identification is unknown
  CMake Error at CMakeLists.txt:3 (ENABLE_LANGUAGE):
    The CMAKE_C_COMPILER:

      cl

    is not a full path and was not found in the PATH.

    To use the NMake generator with Visual C++, cmake must be run from a shell
    that can use the compiler cl from the command line.  This environment is
    unable to invoke the cl compiler.  To fix this problem, run cmake from the
    Visual Studio Command Prompt (vcvarsall.bat).

    Tell CMake where to find the compiler by setting either the environment
    variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
    the compiler, or to the compiler name if it is in the PATH.

  ********************************************************************************
  ----------------------------------------
  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

最佳答案

我已成功解决此错误问题。有两种解决方法,您可以使用其中一种:

  • 将Python 3.9降级为Python 3.8
  • 使用conda而不是pip(如果您已安装python 3.9并且不想降级)

    干杯!

  • 关于python - 错误:无法为使用PEP 517且无法直接安装的opencv-python构建轮子(在PATH中找不到cl),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64373381/

    相关文章:

    python - 使用Python改变numpy数组的维度

    python - pyqtgraph中多个图的链接自动缩放

    Python:使用 json.loads() 读取 json 对象数组

    c++ - 在 CMake/C++ 项目中高效地使用 SublimeText 和 SublimeClang

    python - 如何消除数独方 block 中的凸性缺陷?

    OpenCV 叠加两个图像

    python - 函数内部变量的赋值会改变外部的赋值 - Python

    c++ - 类设计: how to add sequencing or alternating logic to API

    c++ - 如何通过 boost::asio 和 shared_ptr 创建串口

    linux - 如何使用基于linux的平台在windows硬盘上构建linux共享库?