Skip to content

Commit 465b2e0

Browse files
authored
Use sysconfig in Python >= 3.10 (#3764)
* 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 * 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.
1 parent 5f9b090 commit 465b2e0

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

tools/FindPythonLibsNew.cmake

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,24 @@ endif()
112112
# VERSION. VERSION will typically be like "2.7" on unix, and "27" on windows.
113113
execute_process(
114114
COMMAND
115-
"${PYTHON_EXECUTABLE}" "-c" "from distutils import sysconfig as s;import sys;import struct;
115+
"${PYTHON_EXECUTABLE}" "-c" "
116+
import sys;import struct;
117+
import sysconfig as s
118+
USE_SYSCONFIG = sys.version_info >= (3, 10)
119+
if not USE_SYSCONFIG:
120+
from distutils import sysconfig as ds
116121
print('.'.join(str(v) for v in sys.version_info));
117122
print(sys.prefix);
118-
print(s.get_python_inc(plat_specific=True));
119-
print(s.get_python_lib(plat_specific=True));
123+
if USE_SYSCONFIG:
124+
scheme = s.get_default_scheme()
125+
if scheme == 'posix_local':
126+
# Debian's default scheme installs to /usr/local/ but we want to find headers in /usr/
127+
scheme = 'posix_prefix'
128+
print(s.get_path('platinclude', scheme))
129+
print(s.get_path('platlib'))
130+
else:
131+
print(ds.get_python_inc(plat_specific=True));
132+
print(ds.get_python_lib(plat_specific=True));
120133
print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'));
121134
print(hasattr(sys, 'gettotalrefcount')+0);
122135
print(struct.calcsize('@P'));

0 commit comments

Comments
 (0)