• 全网最全的Windows下Anaconda2 / Anaconda3里正确下载安装OpenCV(离线方式和在线方式)(图文详解)
  •   不多说,直接上干货!

     

      说明:

        Anaconda2-5.0.0-Windows-x86_64.exe安装下来,默认的Python2.7

        Anaconda3-4.2.0-Windows-x86_64.exe安装下来,默认的Python3.5

        Anaconda3-5.0.0-Windows-x86_64.exe安装下来,默认的Python3.6

         参考

    全网最全最详细的Windows下安装Anaconda2 / Anaconda3(图文详解)

     

     

     

     

     

     

     

     

      1、  以下是在Windows下Anaconda2里正确下载安装OpenCV(离线方式)

      下载地址 

      因为python装的是Anaconda2版本,所以对应着选择,就安装

      

    https://www.lfd.uci.edu/~gohlke/pythonlibs/

     

     

     

     

     

     

    PS C:Anaconda2Libsite-packages> pip install opencv_python-2.4.13.2-cp27-cp27m-win_amd64.whl
    Processing c:anaconda2libsite-packagesopencv_python-2.4.13.2-cp27-cp27m-win_amd64.whl
    Installing collected packages: opencv-python
    Successfully installed opencv-python-2.4.13.2
    PS C:Anaconda2Libsite-packages>

      测试一下,输python进入python,输入import cv2回车,不报错就说明安装配置成功了 

    PS C:Anaconda2Libsite-packages> python
    Python 2.7.13 |Anaconda, Inc.| (default, Sep 19 2017, 08:25:59) [MSC v.1500 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    >>> import cv2
    >>>

         对于这种方式,我尝试了,是可以行得通的。

     2、 以下是在Windows下Anaconda3里正确下载安装OpenCV(离线方式)

      下载地址 

      因为python装的是Anaconda3版本,所以对应着选择,就安装

     

     

     

     

    PS C:Anaconda3Libsite-packages> pip install opencv_python-3.3.1-cp36-cp36m-win_amd64.whl
    opencv_python-3.3.1-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform.
    PS C:Anaconda3Libsite-packages>

      

        如果还出现这个情况,则换个版本试试。这个很简单,尝试这个版本

     

     

    PS C:Anaconda3Libsite-packages> pip install opencv_python-3.3.0-cp36-cp36m-win_amd64.whl
    Processing c:anaconda3libsite-packagesopencv_python-3.3.0-cp36-cp36m-win_amd64.whl
    Installing collected packages: opencv-python
    Successfully installed opencv-python-3.3.0
    PS C:Anaconda3Libsite-packages>

         成功!这样的安装方式是没问题的。

      import cv2成功。

       

       3、以下是在Windows下Anaconda3里的envs里正确下载安装OpenCV(离线方式)

     

     

    PS C:Anaconda3envspython35Libsite-packages> pip install opencv_python-3.3.0-cp36-cp36m-win_amd64.whl
    Requirement already satisfied: opencv-python==3.3.0 from file:///C:/Anaconda3/envs/python35/Lib/site-packages/opencv_python-3.3.0-cp36-cp36m-win_amd64.whl in c:anaconda3libsite-packages
    PS C:Anaconda3envspython35Libsite-packages>

        一样的,因为这个envs环境是通过如下创建得到的,所以,是寄生在Anaconda3里。

        这种方式,也是成功的。

        如果大家中间有遇到如下的问题,则对应解决。

    C:Userslenovo>python
    Python 3.6.2 |Anaconda custom (64-bit)| (default, Sep 19 2017, 08:03:39) [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    >>> import cv2
    RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: numpy.core.multiarray failed to import
    >>>
    >>> import numpy
    >>> exit()
    
    C:Userslenovo>
    C:Userslenovo>pip install numpy --upgrade
    Exception:
    Traceback (most recent call last):
      File "C:Anaconda3libsite-packagespipasecommand.py", line 215, in main
        status = self.run(options, args)
      File "C:Anaconda3libsite-packagespipcommandsinstall.py", line 335, in run
        wb.build(autobuilding=True)
      File "C:Anaconda3libsite-packagespipwheel.py", line 749, in build
        self.requirement_set.prepare_files(self.finder)
      File "C:Anaconda3libsite-packagespip
    eq
    eq_set.py", line 380, in prepare_files
        ignore_dependencies=self.ignore_dependencies))
      File "C:Anaconda3libsite-packagespip
    eq
    eq_set.py", line 487, in _prepare_file
        req_to_install, finder)
      File "C:Anaconda3libsite-packagespip
    eq
    eq_set.py", line 428, in _check_skip_installed
        req_to_install, upgrade_allowed)
      File "C:Anaconda3libsite-packagespipindex.py", line 465, in find_requirement
        all_candidates = self.find_all_candidates(req.name)
      File "C:Anaconda3libsite-packagespipindex.py", line 423, in find_all_candidates
        for page in self._get_pages(url_locations, project_name):
      File "C:Anaconda3libsite-packagespipindex.py", line 568, in _get_pages
        page = self._get_page(location)
      File "C:Anaconda3libsite-packagespipindex.py", line 683, in _get_page
        return HTMLPage.get_page(link, session=self.session)
      File "C:Anaconda3libsite-packagespipindex.py", line 811, in get_page
        inst = cls(resp.content, resp.url, resp.headers)
      File "C:Anaconda3libsite-packagespipindex.py", line 731, in __init__
        namespaceHTMLElements=False,
    TypeError: parse() got an unexpected keyword argument 'transport_encoding'
    
    C:Userslenovo>

       如果运行下来,还是没得到解决,则

        再尝试下,

      问题出现的原因是numpy的版本较高,不能与opencv2兼容 
      解决办法: 
          pip install -U numpy 
      即可将numpy恢复到合适的版本(这里为1.9.2) 
      再 import cv2 就不会出现上面的问题了。

     

        成功!

        有时候,你可能得卸载Anaconda3里已经安装好了的opencv,再来安装。(为什么呢?是因为你可能没看仔细,下错版本了)

        成功!

        同样,对于如果你是Anaconda3-4.2.0-Windows-x86_64.exe安装下来,默认的Python3.5,则如下

       成功!

      4、以下是在Windows下Anaconda3里正确下载安装OpenCV(在线方式)(注意这里有坑,一定要按照我的来)

    (C:Anaconda3) C:Userslenovo>pip install opencv-python
    Collecting opencv-python
      Cache entry deserialization failed, entry ignored
      Downloading opencv_python-3.3.0.10-cp35-cp35m-win_amd64.whl (39.7MB)
        100% |████████████████████████████████| 39.7MB 25kB/s
    Requirement already satisfied (use --upgrade to upgrade): numpy>=1.11.1 in c:anaconda3libsite-packages (from opencv-python)
    Installing collected packages: opencv-python
    Successfully installed opencv-python-3.3.0.10
    You are using pip version 8.1.2, however version 9.0.1 is available.
    You should consider upgrading via the 'python -m pip install --upgrade pip' command.
    
    (C:Anaconda3) C:Userslenovo>

       验证下,出现如下的错误

    (C:Anaconda3) C:Userslenovo>pip install opencv-python
    Collecting opencv-python
      Cache entry deserialization failed, entry ignored
      Downloading opencv_python-3.3.0.10-cp35-cp35m-win_amd64.whl (39.7MB)
        100% |████████████████████████████████| 39.7MB 25kB/s
    Requirement already satisfied (use --upgrade to upgrade): numpy>=1.11.1 in c:anaconda3libsite-packages (from opencv-python)
    Installing collected packages: opencv-python
    Successfully installed opencv-python-3.3.0.10
    You are using pip version 8.1.2, however version 9.0.1 is available.
    You should consider upgrading via the 'python -m pip install --upgrade pip' command.
    
    (C:Anaconda3) C:Userslenovo>
    (C:Anaconda3) C:Userslenovo>python
    Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul  5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    >>> import cv3
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named 'cv3'
    >>> import cv2
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:Anaconda3libsite-packagescv2\__init__.py", line 9, in <module>
        from .cv2 import *
    ImportError: DLL load failed: 找不到指定的模块。
    >>>

         尝试解决

    >>> import cv2
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:Anaconda3libsite-packagescv2\__init__.py", line 9, in <module>
        from .cv2 import *
    ImportError: DLL load failed: 找不到指定的模块。
    >>> pip install -U numpy
      File "<stdin>", line 1
        pip install -U numpy
                  ^
    SyntaxError: invalid syntax
    >>> exit()
    
    (C:Anaconda3) C:Userslenovo>pip install -U numpy
    Cache entry deserialization failed, entry ignored
    Collecting numpy
      Downloading numpy-1.13.3-cp35-none-win_amd64.whl (13.1MB)
        100% |████████████████████████████████| 13.1MB 74kB/s
    Installing collected packages: numpy
      Found existing installation: numpy 1.11.1
        Uninstalling numpy-1.11.1:
          Successfully uninstalled numpy-1.11.1
    Successfully installed numpy-1.13.3
    You are using pip version 8.1.2, however version 9.0.1 is available.
    You should consider upgrading via the 'python -m pip install --upgrade pip' command.
    
    (C:Anaconda3) C:Userslenovo>
    (C:Anaconda3) C:Userslenovo>

         可以看到,如果你是直接这么来安装,是错误的。为什么呢?按照我的来,先卸载吧。

             需要源文件安装,通过,pip一般都是失败的(经过验证,需要处理下)
     

        于是,我把它给卸载了,带大家来重新做一遍。

     
     

     解决办法:

      https://github.com/skvark/opencv-python/issues/36

         什么意思,很简单。

        (1)下载安装 Visual C++ Redistributable for Visual Studio 2015  不难,别嫌麻烦。

          (2) 把下载的python3.dll放到你所安装Anaconda3的目录下即可。

     

         我的是这样的。

         然后,再尝试pip  install  opencv-python执行完后,再import  cv2就可以成功了

        成功!

      5、也可以直接在Pycharm里搜索并安装Opencv

       这个不多赘述

     

     

    总结

        很多人写的对于OpenCV都是冰山一角,其实没有大家想的那么复杂,只是没有多尝试罢了。

        无论是Python2还是Python3系列,都可以安装,且离线和在线安装成功。

        提醒的是,注意对应自己的版本去安装。

    欢迎大家,加入我的微信公众号:大数据躺过的坑        人工智能躺过的坑
     
     
     

    同时,大家可以关注我的个人博客

       http://www.cnblogs.com/zlslch/   和     http://www.cnblogs.com/lchzls/      http://www.cnblogs.com/sunnyDream/   

       详情请见:http://www.cnblogs.com/zlslch/p/7473861.html

     

      人生苦短,我愿分享。本公众号将秉持活到老学到老学习无休止的交流分享开源精神,汇聚于互联网和个人学习工作的精华干货知识,一切来于互联网,反馈回互联网。
      目前研究领域:大数据、机器学习、深度学习、人工智能、数据挖掘、数据分析。 语言涉及:Java、Scala、Python、Shell、Linux等 。同时还涉及平常所使用的手机、电脑和互联网上的使用技巧、问题和实用软件。 只要你一直关注和呆在群里,每天必须有收获

          对应本平台的讨论和答疑QQ群:大数据和人工智能躺过的坑(总群)(161156071) 

     

  • 相关阅读:
    VS2015安装QT插件
    Spring中的@Transactional(rollbackFor = Exception.class)属性详解
    Ubuntu 安装 k8s 三驾马车 kubelet kubeadm kubectl
    k8s 安装 prometheus 过程记录
    周末没事干就看CSS JS Python ThinkPHP的书,照着例子运行就行,可以增强信心(还有QML,虚拟机运行Web。Windows核心编程,照着例子运行。没事看看socket和rest的例子和文档,还有POCO和BOOST)
    Qt主界面卡死的解决方案一些具体实现方式(五种方法)
    给 ABP vNext 应用安装私信模块
    如何正确的探索 Microsoft Ignite The Tour
    Windows 10 MBR转GPT分区
    Windows 10彻底关闭自动更新
  • 【推广】 阿里云小站-上云优惠聚集地(新老客户同享)更有每天限时秒杀!
    【推广】 云服务器低至0.95折 1核2G ECS云服务器8.1元/月
    【推广】 阿里云老用户升级四重礼遇享6.5折限时折扣!
  • 原文地址:https://www.cnblogs.com/zlslch/p/8059715.html
走看看 - 开发者的网上家园