安装适用于python3的OpenCV [英] Install OpenCV for python3

查看:141
本文介绍了安装适用于python3的OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照许多手册/教程安装

I have followed many manuals/tutorials how to install OpenCV, but all seem to work for my python2.7 instead of python3.4 where I want it. I'm following this tutorial but without using virtualenv. When making the

$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 ..

comand它列出了两个版本:

comand it list both versions:

--   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上的工作能力).

But omits the python_executable flag and uses the python2.7 for building (I checked it worked on python2.7 after continuing with the installation).

如何使它使用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.

But still list the python2.7 to build for.

相关信息:

$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

推荐答案

在删除CMakeCache.txt后,我找到了答案.rm CMakeCache.txt我重新运行cmake命令:

I found the answer, after removing the CMakeCache.txt rm CMakeCache.txtI rerun the cmake command:

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

这篇关于安装适用于python3的OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆