From 5262ff794498b45c12f23f64e9adef30d51e667f Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Mon, 28 Feb 2022 12:49:51 -0400 Subject: [PATCH 1/2] Use sysconfig in Python >= 3.10 Rely on sysconfig for installation paths for Python >= 3.10. distutils has been deprecated and will be removed. Fixes: #3677 --- tools/FindPythonLibsNew.cmake | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/FindPythonLibsNew.cmake b/tools/FindPythonLibsNew.cmake index 7aeffa4412..31eeffa0fc 100644 --- a/tools/FindPythonLibsNew.cmake +++ b/tools/FindPythonLibsNew.cmake @@ -112,11 +112,20 @@ endif() # VERSION. VERSION will typically be like "2.7" on unix, and "27" on windows. execute_process( COMMAND - "${PYTHON_EXECUTABLE}" "-c" "from distutils import sysconfig as s;import sys;import struct; + "${PYTHON_EXECUTABLE}" "-c" " +import sys;import struct; +import sysconfig as s +USE_SYSCONFIG = sys.version_info >= (3, 10) +if not USE_SYSCONFIG: + from distutils import sysconfig as ds print('.'.join(str(v) for v in sys.version_info)); print(sys.prefix); -print(s.get_python_inc(plat_specific=True)); -print(s.get_python_lib(plat_specific=True)); +if USE_SYSCONFIG: + print(s.get_path('platinclude')) + print(s.get_path('platlib')) +else: + print(ds.get_python_inc(plat_specific=True)); + print(ds.get_python_lib(plat_specific=True)); print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO')); print(hasattr(sys, 'gettotalrefcount')+0); print(struct.calcsize('@P')); From 697e8e1fca67bb48e477a61a9bbfa049c653ecd2 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Mon, 28 Feb 2022 13:11:45 -0400 Subject: [PATCH 2/2] Explicitly select the posix_prefix scheme for platinclude on Debian Debian's default scheme is posix_local, for installing locally-built packages to /usr/local/. We want to find the Python headers in /usr/, so search posix_prefix. --- tools/FindPythonLibsNew.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/FindPythonLibsNew.cmake b/tools/FindPythonLibsNew.cmake index 31eeffa0fc..6ad5fe1576 100644 --- a/tools/FindPythonLibsNew.cmake +++ b/tools/FindPythonLibsNew.cmake @@ -121,7 +121,11 @@ if not USE_SYSCONFIG: print('.'.join(str(v) for v in sys.version_info)); print(sys.prefix); if USE_SYSCONFIG: - print(s.get_path('platinclude')) + scheme = s.get_default_scheme() + if scheme == 'posix_local': + # Debian's default scheme installs to /usr/local/ but we want to find headers in /usr/ + scheme = 'posix_prefix' + print(s.get_path('platinclude', scheme)) print(s.get_path('platlib')) else: print(ds.get_python_inc(plat_specific=True));