OpenCV for Python 3.x under Windows [duplicate]
Asked Answered
C

2

21

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.

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.

Cassiecassil answered 21/10, 2014 at 15:0 Comment(4)
opencv3.0 will support python3.xDaph
@Daph I've heard this for a long time, but still i don't see the support in the alpha release on sourceforge. And the document does not specify how to install opencv3 for python 3.x. I wish I can use it now..Cassiecassil
And I only found installation guide for linux for opencv 3 that fits python 3.xCassiecassil
Please check the answers here: #20953773Pygmy
C
7

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.

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.

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

Caprifoliaceous answered 21/10, 2014 at 15:58 Comment(0)
A
44

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:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv

To install, just download the 64-bit or 32-bit .whl file appropriate for your system, then run pip install [filename]. Then the instruction import cv2 should work in your Python 3.x interpreter.

Ashton answered 6/6, 2015 at 19:47 Comment(4)
I managed to install the package but import cv2 failed with No Module named "cv2" error. Did you manage to run it on your windows machine ?Halda
Yes it works for me. Perhaps you have multiple Python installations and you targeted a different one?Ashton
It is working now, had to add pythonpath to point at site_packages. thanks for the help and the great linkHalda
you also need the C++ redistributable for visual studio 2015 at microsoft.com/en-us/download/details.aspx?id=48145Rosiarosicrucian
C
7

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.

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.

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

Caprifoliaceous answered 21/10, 2014 at 15:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.