opencv-python>=4.1.2 not found 报错处理

在跑yolov5s之前出现这个opencv-python的问题

github: skipping check (not a git repository)
requirements: opencv-python>=4.1.2 not found and is required by YOLOv5, attempting auto-update...
ERROR: Invalid requirement: "'opencv-python"
Traceback (most recent call last):
File "D:\yolov5-5.0\utils\general.py", line 110, in check_requirements
pkg.require(r)
File "D:\anaconda\envs\pytorch\lib\site-packages\pkg_resources_init.py", line 909, in require
needed = self.resolve(parse_requirements(requirements))
File "D:\anaconda\envs\pytorch\lib\site-packages\pkg_resources_init
.py", line 795, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'opencv-python>=4.1.2' distribution was not found and is required by the application**

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\yolov5-5.0\train.py", line 500, in
check_requirements()
File "D:\yolov5-5.0\utils\general.py", line 114, in check_requirements
print(subprocess.check_output(f"pip install '{e.req}'", shell=True).decode())
File "D:\anaconda\envs\pytorch\lib\subprocess.py", line 420, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "D:\anaconda\envs\pytorch\lib\subprocess.py", line 524, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'pip install 'opencv-python>=4.1.2'' returned non-zero exit status 1.

但是我的pycharm里面显示的是我的版本是4.5.5

img

这个怎么解决呀

你确定你运行的环境是这个(图里的红框)吗?

img

img

找不到“XX”这类问题,一般优先检查路径环境配置,如果没有问题,那就说明没有安装,重新安装一下就会好

可以参考这篇博文的实例,进行下载:https://blog.csdn.net/qq_45735233/article/details/120088307

conda配置国内的镜像源
修改C:\User\Adminstrater\.condarc 文件如下:

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

conda下载的opencv-python 版本最高是4.0几的,不满足yolov5的需求,所以要用pip下载。

pip install opencv-python

【如果报错,用下面的命令安装】

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python

你需要先用pip安装,安装之后,再在pycharm里安装这个包,最后才能正常使用。

你这是在anaconda里面,你应该去anaconda的终端里面去安装,

img


点击这里的终端,然后在命令行里面输入以下命令,记得一行一行输入。如果你没修改过,pycharm终端默认应该是power shell,这个在win10下面由于安全问题,不能使用conda activate,所以先转到cmd

cmd
conda activate pytorch
pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple 

img

我这里是改过一些东西的,所以ps前面有个(base),可以在ps下面运行conda命令。然后等他安装完毕就可以了.不过你为啥运行yolo5.0的代码,最新的已经是6.2的了,建议使用最新的代码,最少也是6.0的代码,6.0之前的代码不涉及到后面的部署还好,一涉及到部署坑非常多。

参考链接