安装适用于Python的OpenCV(多个python版本) [英] Install OpenCV for Python (multiple python versions)

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

问题描述

我在计算机上安装了两个不同版本的python:2.4和2.7.我正在尝试为2.7版本安装OpenCV(2.4.5).

I have two different versions of python installed on my machine: 2.4 and 2.7. I'm trying to install OpenCV(2.4.5) for the 2.7 version.

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..

它将检测到python 2.4为当前安装:

It detects the python 2.4 as the current installation:

--   Python:
--     Interpreter:                 /usr/bin/python2.4 (ver 2.4)
--     Libraries:                   /usr/lib64/python2.4/config/libpython2.4.a
--     numpy:                       /usr/lib64/python2.4/site-packages/numpy/core/include (ver 1.2.1)
--     packages path:               lib/python2.4/site-packages

后来在构建opencv时出现此错误:

and later in building opencv gives me this error:

[ 75%] Generating pyopencv_generated_funcs.h, pyopencv_generated_func_tab.h, pyopencv_generated_types.h, pyopencv_generated_type_reg.h, pyopencv_generated_const_reg.h
  File "/home/mmoghimi/opencv-2.4.5/modules/python/src2/gen2.py", line 815
    cname1=("cv::Algorithm" if classinfo.isalgorithm else classinfo.cname)))
                             ^
SyntaxError: invalid syntax
make[2]: *** [modules/python/pyopencv_generated_funcs.h] Error 1
make[1]: *** [modules/python/CMakeFiles/opencv_python.dir/all] Error 2
make: *** [all] Error 2

显然,它使用了python2.4不支持的新格式.所以,我的问题是,有什么办法可以明确指定python版本?

apparently it uses a new format that python2.4 does not support. So, my question is that is there any way to explicitly specify the version of python?

推荐答案

有些Cmake标志允许您显式指定要使用的Python版本.您需要将这些标志的值设置为安装Python的正确位置.

There are some Cmake flags which allow you to explicitly specify which version of Python to use. You will need to set the values of these flags to the correct location for your installation of Python.

标志名称和可能的位置如下:

The flag names and likely locations are below:

PYTHON_EXECUTABLE=/usr/bin/python2.7/
PYTHON_INCLUDE=/usr/include/python2.7/
PYTHON_LIBRARY=/usr/lib/libpython2.7.a    //or .so for shared library
PYTHON_PACKAGES_PATH=/usr/local/lib/python2.7/site-packages/
PYTHON_NUMPY_INCLUDE_DIR=/usr/local/lib/python2.7/dist-packages/numpy/core/include

如果这些路径不起作用,则需要在计算机上找到它们.

If these paths don't work, you will need to locate them on your machine.

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

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