19

Has anyone tried to install opencv for python3?. As stated here http://opencv.willowgarage.com/wiki/InstallGuide its support status is unknown. So I want to try it:

I have downloaded the sources for OpenCV-2.3.1. But cmake reports.

-- Python interpreter: /Library/Frameworks/Python.framework/Versions/3.2/bin/python3 -B (ver 3.2)

-- Python numpy: NO (Python wrappers will not be generated)

I do have numpy (version 1.6.0) installed in python3 but cmake does not find it. I am using Mac OSX 10.6 Any ideas?

Update

I just saw one more thing of the cmake output that might be helpful

-- Found PythonInterp: /Library/Frameworks/Python.framework/Versions/3.2/bin/python3 (found version "3.2")

-- Found PythonLibs: /usr/lib/libpython2.6.dylib File "", line 1

from distutils.sysconfig import *; print get_python_lib()

                                                      ^

SyntaxError: invalid syntax File "", line 1

import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print

numpy.distutils.misc_util.get_numpy_include_dirs()[0]

                                                                    ^ 

SyntaxError: invalid syntax File "", line 1

import sphinx; print sphinx.__version__

                          ^ SyntaxError: invalid syntax

Notice that it found 3.2 but then libpython2.6 ??

Any ideas?

Hernan
  • 5,811
  • 10
  • 51
  • 86
  • Note it also needs to find the development headers in an include directory, although I don't know where that should be. – Thomas K Apr 25 '12 at 12:13
  • Sorry to be asking a bit too late but did you manage to have success with your endeavour? – Ishbir Jul 21 '13 at 14:46
  • @Ishbir: Not really, but I haven't really tried in the last 6 months. – Hernan Jul 22 '13 at 15:26
  • Possible duplicate of [OpenCV for Python 3.x under Windows](http://stackoverflow.com/questions/26489867/opencv-for-python-3-x-under-windows) – Michael Currie Mar 10 '16 at 18:53

3 Answers3

10

At the moment OpenCV supports Python 2.x only. OpenCV (including OpenCV 2.4) does not compiles with Python 3.x.

Python3 support is already in wishlist for future versions of OpenCV. But currently there are no activities in this direction and you are welcome to create and contribute a patch resolving the compatibility issues.

Andrey Kamaev
  • 29,582
  • 6
  • 94
  • 88
  • 6
    Actually, I changed some of the cmake files to make them python3 compatible (basically adding parenthesis to print). Now cmake goes through. make does not finish but it seems that there all small thing. The question is which minimum python version you want to support? Dropping support < 2.6 will be great in order to have a single codebase. – Hernan Apr 26 '12 at 14:54
  • 2
    Python3 is supported now from open cv 3.0 onwards – pshirishreddy Jun 30 '15 at 13:51
5

Use the pip application.

On ubuntu:

sudo apt install python3-pip

and so, on command line:

pip3 install --upgrade pip

pip3 install opencv-python

Allan Galdino
  • 121
  • 2
  • 2
4

I got the thing to at least build and install. It can load the cv2 module just fine. Haven't tested too much though.

Details: https://stackoverflow.com/a/21212023/3075814

Community
  • 1
  • 1
midopa
  • 842
  • 7
  • 9