Question: 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 ..

```

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

```

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

```

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?

Answer: 
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.
Use [virtualenv](http://www.virtualenv.org/en/latest/)

```
virtualenv -p python2.7 env
source env/bin/activate
python --version  # prints «Python 2.7.3»
pip install pyopencv

```

If you need support of 2.4 (or other version), just create new environment.