安装opencv时报错:Could not build wheels for opencv-python which use PEP 517 and cannot be installed direc

一、问题背景

        最近写一批程序,需要用到opencv里面的函数,但是导入cv2的时候,新电脑提示没有安装,所以首先安装opencv的库,直接pip install opencv-python,不过报错了。

        然后从镜像站中安装opencv,直接pip install -i https://mirrors.aliyun.com/pypi/simple opencv-python,不过仍然报错,报错原因和上一次一样:Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly

安装opencv时报错:Could not build wheels for opencv-python which use PEP 517 and cannot be installed direc_第1张图片 二、解决办法

        网上找了很多办法,有的说不要用PEP517,有的说不要用默认的路径,有的说从镜像站下载,我都试过了,没有解决问题。

        后来从stackoverflow上找到类似的问题:c++ - ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly (cl was not found in PATH) - Stack Overflow

        回答的建议是:

I have successfully resolved this error issue. There are two methods of going about it, you can use either:

  1. Downgrading Python 3.9 to Python 3.8
  2. Use conda instead of pip (if you have python 3.9 installed and don't want to downgrade)

Cheers!

        要么把python的版本降低,要么用conda安装。

        

        我选择用conda安装,具体解决方案如下:

        (1)首先输入conda install opencv-python,不过报错提示没有找到这个库,可以从它的官网去搜索。

安装opencv时报错:Could not build wheels for opencv-python which use PEP 517 and cannot be installed direc_第2张图片

         从官网搜索opencv的结果如下:

安装opencv时报错:Could not build wheels for opencv-python which use PEP 517 and cannot be installed direc_第3张图片

         (2)安装py-opencv,直接conda install py-opencv就可以了:

安装opencv时报错:Could not build wheels for opencv-python which use PEP 517 and cannot be installed direc_第4张图片

        (3)等安装完成,然后import cv2测试一下,成果导入,没有报错,问题解决:

安装opencv时报错:Could not build wheels for opencv-python which use PEP 517 and cannot be installed direc_第5张图片

 

        

你可能感兴趣的:(python中的报错,opencv,python,计算机视觉)