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 - 尝试使用 OSMnx 在同一图中绘制两个或多个基础设施

    python - 在应用程序之间发送 Canvas 数据

    c++ - 如果应用程序从具有 Windows 管理权限的 cmd 打开,则会出现访问冲突

    python - 从源文件构建 OpenCV 库

    android - 如何从适用于Android的OpenCV中的指针创建FaceRecognizer

    python - 从 json 文件中提取条件值

    python - 可以指定所有位置参数都是一种或其他参数类型吗?

    c++ - 并发对象销毁

    c++ - std::vector 指针?

    opencv - 相机校准后在哪里应用相机矩阵和畸变系数值在新的应用程序?