Python环境安装:Opencv和Numpy

最近在新的电脑上安装Python开发环境,遇到问题并记录:

1.首先安装“Anaconda3-2019.10-Windows-x86_64.exe”,它会自动安装Python环境和pip工具。

2.安装OpenCV之前需要升级Numpy环境,由于装机网速较差,直接使用pip install numpy安装失败,故使用豆瓣的镜像源。

豆瓣镜像地址: https://pypi.douban.com/simple/。

3.安装成功numpy后,仍然使用豆瓣的镜像源安装OpenCV和OpenCV-Contrib。

使用的命令如下:

C:\Users\CTOS>pip install numpy -i "https://pypi.doubanio.com/simple/"
Looking in indexes: https://pypi.doubanio.com/simple/
Collecting numpy
  Downloading https://pypi.doubanio.com/packages/a9/38/f6d6d8635d496d6b4ed5d8ca4b9f193d0edc59999c3a63779cbc38aa650f/numpy-1.18.1-cp37-cp37m-win_amd64.whl (12.8 MB)
     |████████████████████████████████| 12.8 MB 364 kB/s
Installing collected packages: numpy
Successfully installed numpy-1.18.1

C:\Users\CTOS>pip install opencv-python -i "https://pypi.doubanio.com/simple/"
Looking in indexes: https://pypi.doubanio.com/simple/
Collecting opencv-python
  Downloading https://pypi.doubanio.com/packages/5a/af/dabae171f885ec4d9b2fe6aaf74c1d50a8d32106d840b9fb8eb0095a578d/opencv_python-4.2.0.32-cp37-cp37m-win_amd64.whl (33.0 MB)
     |████████████████████████████████| 33.0 MB 437 kB/s
Requirement already satisfied: numpy>=1.14.5 in c:\users\ctos\appdata\local\programs\python\python37\lib\site-packages (from opencv-python) (1.18.1)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.2.0.32

C:\Users\CTOS>pip install opencv-contrib-python -i "https://pypi.doubanio.com/simple/"
Looking in indexes: https://pypi.doubanio.com/simple/
Collecting opencv-contrib-python
  Downloading https://pypi.doubanio.com/packages/ba/bf/1e3a5efff5265d58873d72707487f7204cdab60e77b8deba1eea5f0aea86/opencv_contrib_python-4.2.0.32-cp37-cp37m-win_amd64.whl (39.5 MB)
     |████████████████████████████████| 39.5 MB 123 kB/s
Requirement already satisfied: numpy>=1.14.5 in c:\users\ctos\appdata\local\programs\python\python37\lib\site-packages (from opencv-contrib-python) (1.18.1)
Installing collected packages: opencv-contrib-python
Successfully installed opencv-contrib-python-4.2.0.32

C:\Users\CTOS>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> import numpy as np
>>>
  • 值得注意的是: 如果直接使用“pip install opencv-python -i “https://pypi.doubanio.com/simple/””则由于OpenCV依赖高版本的Numpy,则Numpy的更新仍然需要在原网站下载而导致更新失败。

如果想使用离线安装则需要提前下载好这三个文件:

  1. numpy-1.18.1-cp37-cp37m-win_amd64.whl (12.8 MB)
  2. opencv_python-4.2.0.32-cp37-cp37m-win_amd64.whl (33.0 MB)
  3. opencv_contrib_python-4.2.0.32-cp37-cp37m-win_amd64.whl (39.5 MB)
    a.然后将这三个文件放到“C:\Users\你的用户名”下(也就是初始打开窗口的user路径);然后使用 pip install xxx.whl顺序安装即可。
    b.也可以使用直接 pip install D:\迅雷下载\xxx.whl顺序安装
    c.也可以使用cd 文件下载目录,然后pip install xxx.whl顺序安装

你可能感兴趣的:(经验总结)