Skip to content

Commit

Permalink
Merge pull request #219 from robotology/fixpy312
Browse files Browse the repository at this point in the history
Fix code to obtain Python relative install dir in Python 3.12
  • Loading branch information
traversaro authored Oct 30, 2023
2 parents 071da0d + 69274de commit 246ae16
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ if(ICUB_MODELS_USES_PYTHON)
if(ICUB_MODELS_DETECT_ACTIVE_PYTHON_SITEPACKAGES)
set(PYTHON_INSTDIR ${Python3_SITELIB}/icub_models)
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} _PYTHON_INSTDIR_CLEAN)
set(PYTHON_INSTDIR ${_PYTHON_INSTDIR_CLEAN}/icub_models)
Expand Down

0 comments on commit 246ae16

Please sign in to comment.