Building OpenCV cmake error: could NOT find PythonInterp

时间:2016-04-21 22:09:02

标签: python python-2.7 opencv numpy cmake

To build OpenCV, I ran this in the terminal in my ~/opencv/build directory :

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/path/to/opencv-3.0.0/build -D PYTHON2_LIBRARY=/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin
-D PYTHON2_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers -D PYTHON2_PACKAGES_PATH=/usr/local/lib/python2.7/site-packages -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=/path/to/opencv_contrib-3.0.0/modules ../

But no matter what happens, I see this error in the Traceback : (Could NOT find PythonInterp:)

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named numpy.distutils
-- Could NOT find PythonInterp: Found unsuitable version "2.7.11", 
but required is at least "3.4" (found /usr/local/bin/python)
-- Could NOT find PythonInterp: Found unsuitable version "2.7.11", 
but required is at least "3.2" (found /usr/local/bin/python)

Further down the line, this shows up

-- 
--   Python 2:
--     Interpreter:                 /usr/local/bin/python2.7 (ver 2.7.11)
-- 
--   Python 3:
--     Interpreter:                 NO
-- 
--   Python (for build):            /usr/local/bin/python2.7
-- 
--   Java:
--     ant:                         NO
--     JNI:

The correct output should look somewhat like this: correct Python Interp output

I have tried everything, but this keeps coming up! In essence, I cannot build OpenCV properly, and hence cannot install it properly.

2 个答案:

答案 0 :(得分:3)

你的错误谈到无法找到numpy,所以安装numpy:

pip install numpy

此外,更改您的include目录以确保您实际包含它。对于PYTHON2_INCLUDE_DIR

-D PYTHON2_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers

然后,运行make clean,然后删除您的/build目录,然后再次运行cmake,再make

答案 1 :(得分:0)

您可以手动指定每个Python版本的路径。 enter image description here