在OpenCV linux install doc,部分Building OpenCV from Source Using CMake
據說像如何爲python版本2和3構建OpenCV?
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
運行指令的同時,給出參數的Python:
[optional] Building python. Set the following python parameters:
PYTHON2(3)_EXECUTABLE = <path to python>
PYTHON_INCLUDE_DIR = /usr/include/python<version>
PYTHON_INCLUDE_DIR2 = /usr/include/x86_64-linux-gnu/python<version>
PYTHON_LIBRARY = /usr/lib/x86_64-linux-gnu/libpython<version>.so
PYTHON2(3)_NUMPY_INCLUDE_DIRS = /usr/lib/python<version>/dist-packages/numpy/core/include/
一些參數可以很容易地對兩個Python版本的設置:
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D PYTHON2_EXECUTABLE=/usr/bin/python -D PYTHON3_EXECUTABLE=/usr/bin/python3 ..
但是另一個不明確
PYTHON_INCLUDE_DIR = /usr/include/python<version>
是否可以同時爲兩個版本的Python構建?
你可能想看看'cmake/OpenCVDetectPython.cmake' ...接近底部。有兩套完整的變量,其中一個以'PYTHON2'作爲前綴,另一個以'PYTHON3'作爲前綴。 (例如,我在那裏看到'PYTHON2_INCLUDE_DIR'和'PYTHON3_INCLUDE_DIR')。 –
@DanMašek它在哪裏,看不到? – Dims
https://github.com/opencv/opencv/blob/master/cmake/OpenCVDetectPython.cmake#L225 –