diff --git a/bindings/CMakeLists.txt b/bindings/CMakeLists.txt index ace04e23f6..a229b57d05 100644 --- a/bindings/CMakeLists.txt +++ b/bindings/CMakeLists.txt @@ -47,9 +47,13 @@ if(IDYNTREE_USES_PYTHON OR IDYNTREE_USES_PYTHON_PYBIND11) if(IDYNTREE_DETECT_ACTIVE_PYTHON_SITEPACKAGES) set(IDYNTREE_PYTHON_INSTALL_DIR ${Python3_SITELIB}) else() - execute_process(COMMAND ${Python3_EXECUTABLE} - -c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,0,prefix=''))" - OUTPUT_VARIABLE _PYTHON_INSTDIR) + if(Python3_VERSION VERSION_GREATER_EQUAL 3.12) + execute_process(COMMAND ${Python3_EXECUTABLE} -c "import os;import sysconfig;relative_site_packages = sysconfig.get_path('purelib').replace(sysconfig.get_path('data'), '').lstrip(os.path.sep);print(relative_site_packages)" + OUTPUT_VARIABLE _PYTHON_INSTDIR) + else() + execute_process(COMMAND ${Python3_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(1,0,prefix=''))" + OUTPUT_VARIABLE _PYTHON_INSTDIR) + endif() string(STRIP ${_PYTHON_INSTDIR} IDYNTREE_PYTHON_INSTALL_DIR) endif() endif()