Anaconda 下创建一个python3.6的虚拟环境,进入虚拟环境开始安装:

先安装 opencv-python

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

安装过程:

Looking in indexes: https://pypi.tuna.tsinghua.edu/simple
Collecting opencv-python
  Downloading https://pypi.tuna.tsinghua.edu/packages/48/c3/798bd7b8f78430f82ec0660b753106717e4e4bb8032ce56f77d8577cb24b/opencv_python-4.5.5.64-cp36-abi3-win_amd64.whl (35.4 MB)
     |████████████████████████████████| 35.4 MB 218 kB/s
Collecting numpy>=1.13.3
  Using cached https://pypi.tuna.tsinghua.edu/packages/ea/bc/da526221bc111857c7ef39c3af670bbcf5e69c247b0d22e51986f6d0c5c2/numpy-1.19.5-cp36-cp36m-win_amd64.whl (13.2 MB)
Installing collected packages: numpy, opencv-python
Successfully installed numpy-1.19.5 opencv-python-4.5.5.64

然后安装opencv-contrib-python

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

安装过程

Looking in indexes: https://pypi.tuna.tsinghua.edu/simple
Collecting opencv-contrib-python
  Downloading https://pypi.tuna.tsinghua.edu/packages/2e/63/c02ffce9f182dd77fad7ee1f333a6a2aca1a5a2c14a683d30b5d2bd8d8db/opencv_contrib_python-4.5.5.64-cp36-abi3-win_amd64.whl (42.2 MB)
     |████████████████████████████████| 42.2 MB 311 kB/s
Requirement already satisfied: numpy>=1.13.3 in c:\users\yang\.conda\envs\kivy\lib\site-packages (from opencv-contrib-python) (1.19.5)
Installing collected packages: opencv-contrib-python
Successfully installed opencv-contrib-python-4.5.5.64

此种方法安装后,import cv2 as cv后,代码可以正常运行

更多推荐

python安装opencv的方法(快速简单安装)