[Question] Python not found during compilation

Hi, I’m trying to compile SimpleITK with SimpleElastix in a ubuntu 20.04.6 LTS system. I’ve used the following command as suggested in the documentation:

git clone GitHub - SimpleITK/SimpleITK: SimpleITK: a layer built on top of the Insight Toolkit (ITK), intended to simplify and facilitate ITK's use in rapid prototyping, education and interpreted languages.
mkdir SimpleITK-build
cd SimpleITK-build
cmake -DSimpleITK_USE_ELASTIX=ON -DWRAP_PYTHON:BOOL=ON -DPython_EXECUTABLE=‘which python3’ …/SimpleITK/SuperBuild/
make -j$(nproc)

Note that I only changed the cmake line just to make sure it compile SimpleElastix and the python wheel.
However, every time I try this I always get the same error:

Could NOT find Python (missing: Interpreter Development.Module) (found
version “3.8.10”)

I don’t understand what went wrong as I only have one python3 installed in the system which is python3.8.10 (and I already have installed the python-dev in it’s newest version 3.8.2-0ubuntu2). Dispite I’ve already told cmake where to find it, cmake didn’t seem to have understood?
I’ve tried days and still couldn’t solve this problem, anyone have a solution could really save me from my boss. Many thanks!!!
(I attach the full version of the error message below)

[ 70%] Completed ‘Elastix’
[ 76%] Built target Elastix
[ 77%] Performing configure step for ‘SimpleITK’
Not searching for unused variables given on the command line.
loading initial cache file /home/cedric/Documents/lib/SimpleITK-build/SimpleITK-build/CMakeCacheInit.txt
– Building SimpleITK version “2.4.0.dev142-gc7aa7”
– Processing json files…
– Processing json files…done
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
Could NOT find Python (missing: Interpreter Development.Module) (found
version “3.8.10”)
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.16/Modules/FindPython.cmake:347 (find_package_handle_standard_args)
Wrapping/Python/CMakeLists.txt:7 (find_package)

– Configuring incomplete, errors occurred!
See also “/home/cedric/Documents/lib/SimpleITK-build/SimpleITK-build/CMakeFiles/CMakeOutput.log”.
See also “/home/cedric/Documents/lib/SimpleITK-build/SimpleITK-build/CMakeFiles/CMakeError.log”.
make[2]: *** [CMakeFiles/SimpleITK.dir/build.make:112 : SimpleITK-prefix/src/SimpleITK-stamp/SimpleITK-configure] Erreur 1
make[1]: *** [CMakeFiles/Makefile2:127 : CMakeFiles/SimpleITK.dir/all] Erreur 2
make: *** [Makefile:84 : all] Erreur 2

Hello,

Please ensure that you have the ubuntu package “python3.8-dev” installed. You can this by verifying that “python3.8-config” is installed. Also verify that python3 really is 3.8.

Also I have sometimes seem the FindPython module get confused if there are newer version of python available in the path that don’t have the dev/development module.

You could also try building the package in a docker to isolate issues and have the environment reproducible.