Skip to content

Commit 3232e59

Browse files
authored
Check if module file extension could be queried correctly (#2538)
On very incomplete python installations (e.g. within Docker), it's possible that distutils is not installed. In that case, the ``execute_command`` statement that queries distutils for the Python module extension fails, and pybind11 uses the empty string. This commit adds an extra check that causes a CMake failure with more actionable information (just spent a lot of time trying to track down this problem :))
1 parent 01ad892 commit 3232e59

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tools/pybind11NewTools.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ execute_process(
9191
COMMAND "${${_Python}_EXECUTABLE}" "-c"
9292
"from distutils import sysconfig; print(sysconfig.get_config_var('SO'))"
9393
OUTPUT_VARIABLE _PYTHON_MODULE_EXTENSION
94-
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
94+
ERROR_VARIABLE _PYTHON_MODULE_EXTENSION_ERR
95+
OUTPUT_STRIP_TRAILING_WHITESPACE)
96+
97+
if (_PYTHON_MODULE_EXTENSION STREQUAL "")
98+
message(FATAL_ERROR "pybind11 could not query the module file extension, likely the 'distutils'"
99+
"package is not installed. Full error message:\n${_PYTHON_MODULE_EXTENSION_ERR}")
100+
endif()
95101

96102
# This needs to be available for the pybind11_extension function
97103
set(PYTHON_MODULE_EXTENSION

0 commit comments

Comments
 (0)