安装Opencv-Python和-- Trying ‘MinGW Makefiles‘ generator - failure错误的解决办法

在Python中安装Opencv-Python经常会出现莫名其妙的安装错误,如下:

(yolov5_deepsort) F:\huaweiOBS\Smart-Transportation-System-main>pip install opencv-python -i https://pypi.doubanio.com/simple/
Looking in indexes: https://pypi.doubanio.com/simple/
Collecting opencv-python
  Using cached https://mirrors.cloud.tencent.com/pypi/packages/4a/e7/b70a2d9ab205110d715906fc8ec83fbb00404aeb3a37a0654fdb68eb0c8c/opencv-python-4.10.0.84.tar.gz (95.1 MB)      
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy>=1.13.3 in f:\anaconda\install1\envs\yolov5_deepsort\lib\site-packages (from opencv-python) (1.19.2)
Building wheels for collected packages: opencv-python
  Building wheel for opencv-python (pyproject.toml) ... error
  ERROR: Command errored out with exit status 1:
   command: 'F:\anaconda\install1\envs\yolov5_deepsort\python.exe' 'F:\anaconda\install1\envs\yolov5_deepsort\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py' build_wheel 'C:\Users\86139\AppData\Local\Temp\tmpsfd_v9r3'
       cwd: C:\Users\86139\AppData\Local\Temp\pip-install-yk4djcju\opencv-python_a607267eb1e646f0b22ff1c664f5cbd3
  Complete output (76 lines):


  --------------------------------------------------------------------------------      
  -- Trying 'MinGW Makefiles' generator
  --------------------------------
  ---------------------------
  ----------------------
  -----------------
  ------------
  -------
  --
  Not searching for unused variables given on the command line.
  CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
    Compatibility with CMake < 3.5 will be removed from a future version of
    CMake.

    Update the VERSION argument <min> value or use a ...<max> suffix to tell
    CMake that the project does not need compatibility with older versions.


  -- The C compiler identification is GNU 8.1.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - failed
  -- Check for working C compiler: F:/MinGW/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/bin/gcc.exe
  -- Check for working C compiler: F:/MinGW/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/bin/gcc.exe - broken
  CMake Error at C:/Users/86139/AppData/Local/Temp/pip-build-env-7bdpeqnw/overlay/Lib/site-packages/cmake/data/share/cmake-3.28/Modules/CMakeTestCCompiler.cmake:67 (message):  
    The C compiler

      "F:/MinGW/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/bin/gcc.exe"

    is not able to compile a simple test program.

    It fails with the following output:

      Change Dir: 'C:/Users/86139/AppData/Local/Temp/pip-install-yk4djcju/opencv-python_a607267eb1e646f0b22ff1c664f5cbd3/_cmake_test_compile/build/CMakeFiles/CMakeScratch/TryCompile-iib38z'

      Run Build Command(s): C:/Users/86139/AppData/Local/Temp/pip-build-env-7bdpeqnw/overlay/Lib/site-packages/cmake/data/bin/cmake.exe -E env VERBOSE=1 F:/MinGW/x86_64-8.1.0-release-win32-seh-rt_v6-rev0/mingw64/bin/mingw32-make.exe -f Makefile cmTC_7bf73/fast    
      Access violation





    CMake will not be able to correctly generate this project.
  Call Stack (most recent call first):
    CMakeLists.txt:3 (ENABLE_LANGUAGE)


  -- Configuring incomplete, errors occurred!
  --
  -------
  ------------
  -----------------
  ----------------------
  ---------------------------
  --------------------------------
  -- Trying 'MinGW Makefiles' generator - failure
  --------------------------------------------------------------------------------      

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

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

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

  Or with "Visual Studio 2019":

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

  Or with "Visual Studio 2022":

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

  ********************************************************************************      
  ----------------------------------------
  ERROR: Failed building wheel for opencv-python
Failed to build opencv-python
ERROR: Could not build wheels for opencv-python, which is required to install pyproject.toml-based projects

解决方案:首先更新pip,虽然我也没用到,但是先更新吧,所有教程都说了更新...

首先python -m ensurepip
然后python -m pip install --upgrade pip setuptools wheel即可进行更新

如果执行:pip install opencv-python -i https://pypi.doubanio.com/simple/

这个代码的情况下会下载的opencv版本为tar.gz,由于tar.gz为源代码版本,所以需要MinGW以及CMake编译成源代码才行,多以会发生"-- Trying 'MinGW Makefiles' generator - failure"这样的错误,具体参照下面这篇博文的讲解Python安装包tar.gz和whl文件的区别和说明-CSDN博客文章浏览阅读104次,点赞2次,收藏3次。在Python中安装包可以使用pip install和conda install从源(清华源、阿里源)进行下载并安装,也可以直接下载下来,并在本地进行安装,具体可参照但是两者区别较大,在处理上也有不同。https://blog.csdn.net/qq_52299902/article/details/140904661?spm=1001.2014.3001.5502 从而我们这时候有几种解决方案,第一种解决方案是寻找有二进制安装包、后缀为.whl的源。此处我使用此命令:
pip install opencv-python==4.3.0.38 -i https://pypi.doubanio.com/simple/

注意:opencv的安装一定要与python版本匹配,此版本与我的python3.6匹配,由于其下载的是二进制文件,可以正常进行安装。

第二种方法即是寻找对应的.whl的opencv二进制安装包,然后在本地进行安装。具体可以参照Python本地安装包和Pytorch安装方法-CSDN博客

  • 15
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值