-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
PYTHON3_PACKAGES_PATH converted to absolute path on first CMake run #24141
Description
System Information
OpenCV version: 4.8.0
Operation System / Patform: Windows 11
Compiler & compiler version: Visual Studio 2022
Detailed description
The CMake scripts to configure the PYTHON3_PACKAGES_PATH generally support both, absolute and relative paths for the latter. In particular, the generated config.py of the cv2 module will contain the correct path pointing to the OpenCV libraries in both cases, either as an absolute or relative path, respectively, depending on an absolute or relative prefix.
However, running CMake with a user-defined, relative PYTHON3_PACKAGES_PATH always replaces it with an absolute path during the first run:
git clone https://github.com/opencv/opencv.git OpenCV
cmake -S . -B build -D "PYTHON3_PACKAGES_PATH=python"
This generates the following build configuration:
-- Python 3:
-- Interpreter: C:/Program Files/Python/python.exe (ver 3.10.11)
-- Libraries: C:/Program Files/Python/libs/python310.lib (ver 3.10.11)
-- numpy: C:/Program Files/Python/lib/site-packages/numpy/core/include (ver 1.23.5)
-- install path: C:/OpenCV/python/cv2/python-3.10
Note that the install path defined by PYTHON3_PACKAGES_PATH contains the source directoy as a prefix, C:/OpenCV here. After re-running cmake with the same arguments, the relative path is set correctly:
cmake -S . -B build -D "PYTHON3_PACKAGES_PATH=python"
-- Python 3:
-- Interpreter: C:/Program Files/Python/python.exe (ver 3.10.11)
-- Libraries: C:/Program Files/Python/libs/python310.lib (ver 3.10.11)
-- numpy: C:/Program Files/Python/lib/site-packages/numpy/core/include (ver 1.23.5)
-- install path: python/cv2/python-3.10
We investigated the issue already. Here, PYTHON3_PACKAGES_PATH is set by find_python() inside OpenCVDetectPython.cmake and it seems that this function does not properly handle absolute and relative prefixes. Still, we wanted to report this bug first. We think that something needs to be fixed here, running CMake twice is a rather unsatisfying workaround. Or does somebody know a different solution for this issue?
Steps to reproduce
- Clone the repository
- Run CMake first with
PYTHON3_PACKAGES_PATHset to a relative path converts the path to an absolute path. - Re-run CMake with the same commands and the path correctly remains relative.
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files (videos, images, onnx, etc)