不多说,直接上干货!
说明:
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版本,所以对应着选择,就安装
PS C:\Anaconda2\Lib\site-packages> pip install opencv_python-2.4.13.2-cp27-cp27m-win_amd64.whl Processing c:\anaconda2\lib\site-packages\opencv_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:\Anaconda2\Lib\site-packages>
测试一下,输python
进入python,输入import cv2
回车,不报错就说明安装配置成功了
PS C:\Anaconda2\Lib\site-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:\Anaconda3\Lib\site-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:\Anaconda3\Lib\site-packages>
如果还出现这个情况,则换个版本试试。这个很简单,尝试这个版本
PS C:\Anaconda3\Lib\site-packages> pip install opencv_python-3.3.0-cp36-cp36m-win_amd64.whl Processing c:\anaconda3\lib\site-packages\opencv_python-3.3.0-cp36-cp36m-win_amd64.whl Installing collected packages: opencv-python Successfully installed opencv-python-3.3.0 PS C:\Anaconda3\Lib\site-packages>
3、以下是在Windows下Anaconda3里的envs里正确下载安装OpenCV(离线方式)
PS C:\Anaconda3\envs\python35\Lib\site-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:\anaconda3\lib\site-packages PS C:\Anaconda3\envs\python35\Lib\site-packages>
一样的,因为这个envs环境是通过如下创建得到的,所以,是寄生在Anaconda3里。
C:\Users\lenovo>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:\Users\lenovo> C:\Users\lenovo>pip install numpy --upgrade Exception: Traceback (most recent call last): File "C:\Anaconda3\lib\site-packages\pip\basecommand.py", line 215, in main status = self.run(options, args) File "C:\Anaconda3\lib\site-packages\pip\commands\install.py", line 335, in run wb.build(autobuilding=True) File "C:\Anaconda3\lib\site-packages\pip\wheel.py", line 749, in build self.requirement_set.prepare_files(self.finder) File "C:\Anaconda3\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files ignore_dependencies=self.ignore_dependencies)) File "C:\Anaconda3\lib\site-packages\pip\req\req_set.py", line 487, in _prepare_file req_to_install, finder) File "C:\Anaconda3\lib\site-packages\pip\req\req_set.py", line 428, in _check_skip_installed req_to_install, upgrade_allowed) File "C:\Anaconda3\lib\site-packages\pip\index.py", line 465, in find_requirement all_candidates = self.find_all_candidates(req.name) File "C:\Anaconda3\lib\site-packages\pip\index.py", line 423, in find_all_candidates for page in self._get_pages(url_locations, project_name): File "C:\Anaconda3\lib\site-packages\pip\index.py", line 568, in _get_pages page = self._get_page(location) File "C:\Anaconda3\lib\site-packages\pip\index.py", line 683, in _get_page return HTMLPage.get_page(link, session=self.session) File "C:\Anaconda3\lib\site-packages\pip\index.py", line 811, in get_page inst = cls(resp.content, resp.url, resp.headers) File "C:\Anaconda3\lib\site-packages\pip\index.py", line 731, in __init__ namespaceHTMLElements=False, TypeError: parse() got an unexpected keyword argument 'transport_encoding' C:\Users\lenovo>
如果运行下来,还是没得到解决,则
再尝试下,
问题出现的原因是numpy的版本较高,不能与opencv2兼容
解决办法:
pip install -U numpy
即可将numpy恢复到合适的版本(这里为1.9.2)
再 import cv2 就不会出现上面的问题了。
有时候,你可能得卸载Anaconda3里已经安装好了的opencv,再来安装。
以下是在Windows下Anaconda3里正确下载安装OpenCV(在线方式)
(C:\Anaconda3) C:\Users\lenovo>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:\anaconda3\lib\site-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:\Users\lenovo>
验证下,出现如下的错误
(C:\Anaconda3) C:\Users\lenovo>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:\anaconda3\lib\site-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:\Users\lenovo> (C:\Anaconda3) C:\Users\lenovo>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:\Anaconda3\lib\site-packages\cv2\__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:\Anaconda3\lib\site-packages\cv2\__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:\Users\lenovo>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:\Users\lenovo> (C:\Anaconda3) C:\Users\lenovo>
![](https://i-blog.csdnimg.cn/blog_migrate/9c805687ee7868d7c63efb77283f92c3.png)
于是,我把它给卸载
总结
如果你是Anaconda2,则现在默认是Python2.7,那么可以直接在
参考
http://blog.csdn.net/lwplwf/article/details/61616493
http://blog.csdn.net/zstarwalker/article/details/72855781