Repository: opencv
Issue: cmake not detecting correct python3.8 version where python3.7 is also installed.
Labels: category: build/install,category: 3rdparty

I'm trying to build opencv for 3.8 where python 3.7 is also installed. Is it possible?
```
$ . ~/venv/p38_opencv/bin/activate  # Select python3.8
$ python --version
Python 3.8.13
```

What I'm running into is that cmake seems has a mismatch between the python interpret and and the detected python version somehow. The output of cmake:

```
--   Python 3:
--     Interpreter:                 /home/sir/venv/p38_opencv/bin/python3.8 (ver 3.7.5)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.8.so (ver 3.7.5)
--     numpy:                       /home/sir/venv/p38_opencv/lib/python3.8/site-packages/numpy/core/include (ver 1.16.1)
--     install path:                lib/python3.7/site-packages/cv2/python-3.7
```

python3.8 was asked for, but ver 3.7.5 (also installed) was detected.
Similarly, I'm specifying the venv installed numpy with: PYTHON3_NUMPY_INCLUDE_DIRS=/home/sir/venv/p38_opencv/lib/python3.8/site-packages/numpy/core/include
... yet the system version (1.16.1) is detected.


This is under ubuntu 18.04 with python3.8 explicitly installed.

```
. ~/venv/p38_opencv/bin/activate  # Select python3.8
cd  ~/opencv-4.x/build/
 cmake -D CMAKE_BUILD_TYPE=RELEASE  \
  -D CMAKE_INSTALL_PREFIX=/usr/local \
 -D OPENCV_EXTRA_MODULES_PATH=/home/sir/opencv_contrib/modules \
 -D OPENCV_GENERATE_PKGCONFIG=ON \
 -D BUILD_NEW_PYTHON_SUPPORT=ON \
 -D PYTHON3_EXECUTABLE=/home/sir/venv/p38_opencv/bin/python3.8 \
 -D PYTHON3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.8.so \
 -D PYTHON3_LIBRARIES=/usr/lib/x86_64-linux-gnu/libpython3.8.so \
 -D PYTHON3_INCLUDE_DIR=/usr/include/python3.8 \
 -D PYTHON3_INCLUDE_PATH=/usr/include/python3.8 \
 -D PYTHON3_NUMPY_INCLUDE_DIRS=/home/sir/venv/p38_opencv/lib/python3.8/site-packages/numpy/core/include \
 -D OPENCV_PYTHON_INSTALL_PATH_SETUPVARS=/home/sir/venv/p38_opencv/lib/python3.8/site-packages \
 -D INSTALL_PYTHON_EXAMPLES=OFF \
 -D INSTALL_C_EXAMPLES=OFF -D BUILD_EXAMPLES=OFF \
  ..
```

In fact, I see a lot of references to 3.7:
```
~/opencv-4.x/build$ grep -R PYTHON3 | grep 3.7
CMakeCache.txt:PYTHON3_PACKAGES_PATH:PATH=lib/python3.7/site-packages
CMakeCache.txt:PYTHON3LIBS_VERSION_STRING:INTERNAL=3.7.5
CMakeCache.txt:PYTHON3_VERSION_STRING:INTERNAL=3.7.5
CMakeCache.txt:__INSTALL_PATH_PYTHON3:INTERNAL=lib/python3.7/site-packages/cv2/python-3.7
CMakeVars.txt:PYTHON3LIBS_VERSION_STRING=3.7.5
CMakeVars.txt:PYTHON3_PACKAGES_PATH=lib/python3.7/site-packages
CMakeVars.txt:PYTHON3_VERSION_STRING=3.7.5

~/opencv-4.x/build$  grep -R FIND_PACKAGE | grep Python
CMakeCache.txt:FIND_PACKAGE_MESSAGE_DETAILS_PythonInterp:INTERNAL=[/usr/bin/python3.7][v3.7.5(3.2)]
CMakeCache.txt:FIND_PACKAGE_MESSAGE_DETAILS_PythonLibs:INTERNAL=[/usr/lib/x86_64-linux-gnu/libpython3.7m.so][/usr/include/python3.7][v3.7.5(3.7.5)]
CMakeVars.txt:FIND_PACKAGE_MESSAGE_DETAILS_PythonInterp=[/usr/bin/python3.7][v3.7.5(3.2)]
CMakeVars.txt:FIND_PACKAGE_MESSAGE_DETAILS_PythonLibs=[/usr/lib/x86_64-linux-gnu/libpython3.7m.so][/usr/include/python3.7][v3.7.5(3.7.5)]
```

And for numpy I see:
```
# This is installed with pip, version 1.22.4
CMakeVars.txt:PYTHON3_NUMPY_INCLUDE_DIRS=/home/sir/venv/p38_opencv/lib/python3.8/site-packages/numpy/core/include

# system's Python 3.7 version:
CMakeVars.txt:PYTHON3_NUMPY_VERSION=1.16.1
```

I'm using the latest cmake (I read earlier version don't detect python correcty).
```
$ cmake --version
cmake version 3.23.2
```