我已经按照许多手册/教程如何安装OpenCV,但所有似乎都适用于我的python2.7而不是我想要的python3.4。我关注this教程,但没有使用virtualenv。在制作
时$cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D BUILD_EXAMPLES=ON \
-D PYTHON_EXECUTABLE=/usr/bin/python3.4 \
-D PYTHON_PACKAGES_PATHS=/usr/local/lib/python3.4/dist-packages/ \
-D PYTHON_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3.4/dist-packages/numpy/core/include ..
命令它列出两个版本:
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 3.4.3)
-- Libraries: NO
-- numpy: /usr/local/lib/python2.7/dist-packages/numpy/core/include (ver 1.10.4)
-- packages path: lib/python2.7/dist-packages
--
-- Python 3:
-- Interpreter: /usr/bin/python3.4 (ver 3.4.3)
-- Libraries: NO
-- numpy: /usr/local/lib/python3.4/dist-packages/numpy/core/include (ver 1.10.4)
-- packages path: lib/python3.4/dist-packages
--
-- Python (for build): /usr/bin/python2.7
但是省略了python_executable标志并使用python2.7进行构建(我在继续安装后检查了它在python2.7上工作)。
如何使用python3.4进行构建?
我尝试的事情:
运行此cmake时:
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \
-D PYTHON_EXECUTABLE=$(which python3) ..
它正确列出了库:
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 3.4.3)
-- Libraries: NO
-- numpy: /usr/local/lib/python2.7/dist-packages/numpy/core/include (ver 1.10.4)
-- packages path: lib/python2.7/dist-packages
--
-- Python 3:
-- Interpreter: /usr/bin/python3.4 (ver 3.4.3)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (ver 3.4.3)
-- numpy: /usr/local/lib/python3.4/dist-packages/numpy/core/include (ver 1.10.4)
-- packages path: lib/python3.4/dist-packages
--
-- Python (for build): /usr/bin/python2.7
但仍然列出要构建的python2.7。
相关信息:
$whereis python3
python3: /usr/bin/python3.4dm-config /usr/bin/python3.4m /usr/bin/python3.4m-config /usr/bin/python3.4-config /usr/bin/python3 /usr/bin/python3.4-dbg-config /usr/bin/python3.4 /usr/bin/python3.4-dbg /usr/bin/python3.4dm /etc/python3 /etc/python3.4 /usr/lib/python3.0 /usr/lib/python3.5 /usr/lib/python3 /usr/lib/python3.4 /usr/lib/python3.2 /usr/lib/python3.1 /usr/lib/python3.3 /usr/bin/X11/python3.4dm-config /usr/bin/X11/python3.4m /usr/bin/X11/python3.4m-config /usr/bin/X11/python3.4-config /usr/bin/X11/python3 /usr/bin/X11/python3.4-dbg-config /usr/bin/X11/python3.4 /usr/bin/X11/python3.4-dbg /usr/bin/X11/python3.4dm /usr/local/lib/python3.4 /usr/include/python3.4m /usr/include/python3.4 /usr/include/python3.4dm /usr/share/python3 /usr/share/man/man1/python3.1.gz
答案 0 :(得分:5)
我找到了答案,在删除CMakeCache.txt rm CMakeCache.txt
后,我重新运行了cmake命令:
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \
-D PYTHON_EXECUTABLE=/usr/bin/python3.4 \
-D BUILD_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D INSTALL_PYTHON_EXAMPLES=ON ..
输出结果为:
-- Python 2:
-- Interpreter: /usr/bin/python3.4 (ver 3.4.3)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (ver 3.4.3)
-- numpy: /usr/local/lib/python3.4/dist-packages/numpy/core/include (ver 1.10.4)
-- packages path: lib/python3.4/dist-packages
--
-- Python 3:
-- Interpreter: /usr/bin/python3.4 (ver 3.4.3)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (ver 3.4.3)
-- numpy: /usr/local/lib/python3.4/dist-packages/numpy/core/include (ver 1.10.4)
-- packages path: lib/python3.4/dist-packages
--
-- Python (for build): /usr/bin/python3.4
--
所以我坚持安装:
make -j4
sudo make install
sudo ldconfig