Windows 下 Python 3.x 的 OpenCV
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26489867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OpenCV for Python 3.x under Windows
提问by shelper
I've been searching around the Internet for a while but I have not been able to find detailed instructions on how to install OpenCV for Python 3.x under Windows.
我已经在互联网上搜索了一段时间,但我一直无法找到有关如何在 Windows 下为 Python 3.x 安装 OpenCV 的详细说明。
I would really appreciate if anyone here can share his/her method if he/she had successfully installed OpenCV for Python 3.x, either from a pre-built binary or from the source code, for either version OpenCV 2.x or OpenCV 3.x.
如果这里有人可以分享他/她的方法,如果他/她已经成功地从预构建的二进制文件或源代码安装了 OpenCV for Python 3.x,无论是 OpenCV 2.x 还是 OpenCV 3 版本,我都将不胜感激。X。
采纳答案by Connor H
OpenCV 3 added python 3+ support. It is still in alpha and there are a lot of known bugs with it and python at the moment. The final version of OpenCV 3 will be released by the end of the year.
OpenCV 3 添加了 python 3+ 支持。它仍处于 alpha 阶段,目前它和 python 有很多已知的错误。OpenCV 3 的最终版本将于年底发布。
If you download the OpenCV 3 alpha executable from the website, you can build the support for python 3. Alternatively, you can get the latest code from their github. You will also have to install CMake and Python 3. Open up CMake and it will ask where the source code is. If you downloaded the executable, it will be located where ever you extracted the executable at in the sources folder. If you downloaded the latest build, it is wherever you downloaded that. Select the folder and in CMake, hit configure and it will ask you which compiler you want to use. After that, you can see everything you can build in OpenCV. As of OpenCV 3, there is an option for Python3. Check that and anything else you might want, and hit generate. That will make a project within your compiler of choice that you can build, and that will build all of the library's you need.
如果您从网站下载 OpenCV 3 alpha 可执行文件,您可以构建对 python 3 的支持。或者,您可以从他们的 github 获取最新代码。您还必须安装 CMake 和 Python 3。打开 CMake,它会询问源代码在哪里。如果您下载了可执行文件,它将位于您在源文件夹中提取可执行文件的位置。如果您下载了最新版本,那么它就在您下载的任何位置。选择文件夹并在 CMake 中,点击配置,它会询问您要使用哪个编译器。之后,您可以看到可以在 OpenCV 中构建的所有内容。从 OpenCV 3 开始,有一个适用于 Python3 的选项。检查那个和你可能想要的任何其他东西,然后点击生成。这将在您选择的编译器中创建一个您可以构建的项目,并将构建所有库'
While this guide is made for 2.4.9, it works for 3.0. You will just see different options within 3. http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html
虽然本指南是为 2.4.9 制作的,但它适用于 3.0。您只会在 3 个中看到不同的选项。 http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html
回答by Michael Currie
For those on Windows who don't want to mess with building OpenCV 3.0 from source, Christoph Gohlke maintains Windows binaries for many Python packages, including OpenCV 3.0 with Python 3.x bindings! See here:
对于那些不想从源代码构建 OpenCV 3.0 的 Windows 用户,Christoph Gohlke 为许多 Python 包维护了 Windows 二进制文件,包括带有 Python 3.x 绑定的 OpenCV 3.0!看这里:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
To install, just download the 64-bit or 32-bit .whlfile appropriate for your system, then run pip install [filename]. Then the instruction import cv2should work in your Python 3.x interpreter.
要安装,只需下载.whl适合您系统的 64 位或 32 位文件,然后运行pip install [filename]. 然后该指令import cv2应该在您的 Python 3.x 解释器中工作。
回答by Rosa Alejandra
For Windows users, I strongly recommend forgetting about Python 3.x and install WinPython 2.7https://sourceforge.net/projects/winpython/files/WinPython_2.7/2.7.10.3/
对于 Windows 用户,我强烈建议忘记 Python 3.x 并安装WinPython 2.7 https://sourceforge.net/projects/winpython/files/WinPython_2.7/2.7.10.3/
then, after installing opencv, just move the file opencv\build\python\x86\2.7\cv2.pydto *WinPython-64bit-2.7.6.3\python-2.7.6\Lib\site-packages*
然后,安装 opencv 后,只需将文件opencv\build\python\x86\2.7\cv2.pyd 移动到 *WinPython-64bit-2.7.6.3\python-2.7.6\Lib\site-packages*
Now, open Spyder.exe, found in your WinPython folder, and execute (
现在,打开在 WinPython 文件夹中找到的 Spyder.exe,然后执行 (
import cv2
print cv2.__version__
This is the easiest way to have opencv running on windows.
这是在 Windows 上运行 opencv 的最简单方法。

