Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distutils removed in Python3.12 #1047

Open
Jacobfaib opened this issue Dec 13, 2023 · 2 comments
Open

distutils removed in Python3.12 #1047

Jacobfaib opened this issue Dec 13, 2023 · 2 comments

Comments

@Jacobfaib
Copy link

Jacobfaib commented Dec 13, 2023

Python 3.12 removes distutils, and this is causing some grief with the cmake utilities shipped with scikit-build, which result in the following cmake errors:

Traceback (most recent call last):
  File "<string>", line 2, in <module>
  ModuleNotFoundError: No module named 'distutils'
  CMake Error at
  /path/toskbuild/resources/cmake/FindPythonExtensions.cmake:304
   (list):
  list GET given empty list

The following patch addresses this in a backwards compatible way:

--- FindPythonExtensions.old.cmake	2023-12-13 13:05:03
+++ FindPythonExtensions.cmake	2023-12-13 13:06:16
@@ -254,19 +254,23 @@
 include(targetLinkLibrariesWithDynamicLookup)

 set(_command "
-import distutils.sysconfig
+import sys
+
+if sys.version_info >= (3, 10):
+    import sysconfig
+else:
+    import distutils.sysconfig as sysconfig
 import itertools
 import os
 import os.path
 import site
-import sys

 result = None
 rel_result = None
 candidate_lists = []

 try:
-    candidate_lists.append((distutils.sysconfig.get_python_lib(),))
+    candidate_lists.append((sysconfig.get_python_lib(),))
 except AttributeError: pass

 try:
@@ -293,7 +297,7 @@
     sys.prefix,
     result,
     rel_result,
-    distutils.sysconfig.get_config_var('EXT_SUFFIX')
+    sysconfig.get_config_var('EXT_SUFFIX')
 )))
 ")
@henryiii
Copy link
Contributor

This actually isn't quite this easy, since this value was broken before 3.8.7. So this is necessary:

https://github.com/scikit-build/scikit-build-core/blob/565bd6b67f730acc30f982059b507c04e98fa40f/src/scikit_build_core/builder/sysconfig.py#L153-L159

@henryiii
Copy link
Contributor

Ahh, missed you already had a version-based if there, only saw the bottom part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants