最近在一个新环境上 import cv2 时,报了找不到包的错误,自然地就用 PyCharm 安装 cv2(install package cv2),但是最后却报了错:Collecting cv2 Could not find a version that satisfies the requirement cv2 (from versions: ) No matching distribution found for cv2,本文分享下报错的原因以及解决方法。
一、问题描述
Python 版本:Python 3.7.3
在 PyCharm 上 import cv2 时,红色波浪线报错找不到 cv2,快捷键 option + return
选择解决方案“install package cv2”,最后提示错误如下:
Collecting cv2 Could not find a version that satisfies the requirement cv2 (from versions: ) No matching distribution found for cv2
同样的,在 install opencv 时,报错如下:
Collecting opencv Could not find a version that satisfies the requirement opencv (from versions: ) No matching distribution found for opencv
二、问题解决
其实这个问题的原因很简单,cv2 和 opencv 并不是包名,它们俩都是 opencv-python 的一部分,所以我们应该直接安装 opencv-python。
如果你在用 Python2:
pip install opencv-python
如果你在用 Python3:
pip3 install opencv-python