【问题标题】:Failed to build opencv-python无法构建 opencv-python
【发布时间】:2020-12-04 00:21:26
【问题描述】:

我正在使用 pycharm。我创建了一个虚拟环境来使用,当我尝试安装 opencv 库时,我收到一条错误消息。

我正在使用pip命令安装openCV:

命令:pip install opencv-python

这是我使用命令时出现的错误信息:

错误:-

Collecting opencv-python
  Using cached https://files.pythonhosted.org/packages/e0/6f/237b730227927c15a68ec831a51bc83837bb65d54bf9651c08b474201b9a/opencv-python-4.4.0.40.tar.gz
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: numpy>=1.17.3 in f:\python\rio python\project rio\reco_env\lib\site-packages (from opencv-python) (1.19.1)
Building wheels for collected packages: opencv-python
  Building wheel for opencv-python (PEP 517) ... error
  Complete output from command "F:\Python\Rio Python\Project Rio\Reco_env\Scripts\python.exe" "F:\Python\Rio Python\Project Rio\Reco_env\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_vendor\pep517\_in_process.py" build_wheel C:\Users\Rio\AppData\Local\Temp\tmpew_pbwjp:
  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/Rio/AppData/Local/Temp/pip-install-gyo_26q6/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

    could not find any instance of Visual Studio.



  -- Configuring incomplete, errors occurred!
  See also "C:/Users/Rio/AppData/Local/Temp/pip-install-gyo_26q6/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.


  -- Configuring incomplete, errors occurred!
  See also "C:/Users/Rio/AppData/Local/Temp/pip-install-gyo_26q6/opencv-python/_cmake_test_compile/build/CMakeFiles/CMakeOutput.log".
  See also "C:/Users/Rio/AppData/Local/Temp/pip-install-gyo_26q6/opencv-python/_cmake_test_compile/build/CMakeFiles/CMakeError.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 JOM 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.


  -- Configuring incomplete, errors occurred!
  See also "C:/Users/Rio/AppData/Local/Temp/pip-install-gyo_26q6/opencv-python/_cmake_test_compile/build/CMakeFiles/CMakeOutput.log".
  See also "C:/Users/Rio/AppData/Local/Temp/pip-install-gyo_26q6/opencv-python/_cmake_test_compile/build/CMakeFiles/CMakeError.log".


  --------------------------------------------------------------------------------
  -- Trying "Ninja (Visual Studio 15 2017 v141)" generator
  --------------------------------
  ---------------------------
  ----------------------
  -----------------
  ------------
  -------
  --
  --
  -------
  ------------
  -----------------
  ----------------------
  ---------------------------
  --------------------------------
  -- Trying "Ninja (Visual Studio 15 2017 v141)" generator - failure
  --------------------------------------------------------------------------------



  --------------------------------------------------------------------------------
  -- Trying "Visual Studio 15 2017 v141" generator
  --------------------------------
  ---------------------------
  ----------------------
  -----------------
  ------------
  -------
  --
  --
  -------
  ------------
  -----------------
  ----------------------
  ---------------------------
  --------------------------------
  -- Trying "Visual Studio 15 2017 v141" generator - failure
  --------------------------------------------------------------------------------



  --------------------------------------------------------------------------------
  -- Trying "NMake Makefiles (Visual Studio 15 2017 v141)" generator
  --------------------------------
  ---------------------------
  ----------------------
  -----------------
  ------------
  -------
  --
  --
  -------
  ------------
  -----------------
  ----------------------
  ---------------------------
  --------------------------------
  -- Trying "NMake Makefiles (Visual Studio 15 2017 v141)" generator - failure
  --------------------------------------------------------------------------------



  --------------------------------------------------------------------------------
  -- Trying "NMake Makefiles JOM (Visual Studio 15 2017 v141)" generator
  --------------------------------
  ---------------------------
  ----------------------
  -----------------
  ------------
  -------
  --
  --
  -------
  ------------
  -----------------
  ----------------------
  ---------------------------
  --------------------------------
  -- Trying "NMake Makefiles JOM (Visual Studio 15 2017 v141)" generator - failure
  --------------------------------------------------------------------------------

  ********************************************************************************
  scikit-build could not get a working generator for your system. Aborting build.

  Building windows wheels for Python 3.8 requires Microsoft Visual Studio 2017.
  Get it with "Visual Studio 2017":

    https://visualstudio.microsoft.com/vs/

  ********************************************************************************

  ----------------------------------------
  Failed building wheel for opencv-python
  Running setup.py clean for opencv-python
Failed to build opencv-python
Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly

我还安装了 Visual Studio Community 2019,并尝试使用 Visual Studio Community 2017,但我仍然遇到同样的问题。

请问有人知道怎么解决吗?

【问题讨论】:

    标签: python opencv pycharm


    【解决方案1】:

    解决方案:pip3 install --upgrade pip setuptools wheel

    【讨论】:

    • 为什么是这样的解决方案? IE。它是如何工作的,为什么它应该解决这个问题。请理解,在这里解释的答案比仅代码的答案更容易被理解。
    【解决方案2】:

    安装 anaconda...我也遇到了同样的问题...但是 anaconda 解决了问题

    【讨论】:

    • 我已经安装了anaconda,并且在我的vs代码中,当我在虚拟环境中安装时没有问题。我正在使用 pycharm 构建迷你项目,但我遇到了这个问题
    【解决方案3】:

    我相信您的问题正在发生,因为 Cmake 在您的系统路径中找不到 cl 编译器。尝试根据您安装的 Visual Studio 找到它,然后将其添加到您的系统路径。

    这是可以找到 cl.exe 的路径示例。现在我的是 14.0,但你的可能不同。

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin
    

    【讨论】:

    • C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\bin\Hostx64\x64 我现在在这个位置找到了 cl.exe 文件接下来呢?
    • 检查此链接:stackoverflow.com/questions/44272416/… 您可以跳过接受的答案中显示的第一步(其他答案说明如何)
    猜你喜欢
    • 2013-11-29
    • 2021-04-16
    • 2017-05-10
    • 2018-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-22
    相关资源
    最近更新 更多