CMAKE can't find Python3 because Development.Module is missing.

I’m trying to compile ElmerFEMGUI with VTK as a dependency; however, VTK’s cmake files are failing to find the Developmentm.Module requirement. The executable is found.

The error call stack is as follows

CMake Error at /usr/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Python3 (missing: Development.Module)
Call Stack (most recent call first):
  /usr/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.26/Modules/FindPython/Support.cmake:3766 (find_package_handle_standard_args)
  /usr/share/cmake-3.26/Modules/FindPython3.cmake:551 (include)
  /usr/local/lib/cmake/vtk-9.2/VTK-vtk-module-find-packages.cmake:303 (find_package)
  /usr/local/lib/cmake/vtk-9.2/vtk-config.cmake:152 (include)
  ElmerGUI/CMakeLists.txt:106 (FIND_PACKAGE)

I have python3.9-dev and python3.9 installed. For reference I can demonstrate this through dpkg -l python3.* which produces

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                      Version                 Architecture Description
+++-=========================-=======================-============-============================================================================
un  python3.1                 <none>                  <none>       (no description available)
un  python3.6-2to3            <none>                  <none>       (no description available)
un  python3.7-2to3            <none>                  <none>       (no description available)
ii  python3.8                 3.8.10-0ubuntu1~20.04.8 amd64        Interactive high-level object-oriented language (version 3.8)
un  python3.8-apt             <none>                  <none>       (no description available)
un  python3.8-cairo           <none>                  <none>       (no description available)
un  python3.8-cups            <none>                  <none>       (no description available)
un  python3.8-dbus            <none>                  <none>       (no description available)
ii  python3.8-dev             3.8.10-0ubuntu1~20.04.8 amd64        Header files and a static library for Python (v3.8)
un  python3.8-distutils       <none>                  <none>       (no description available)
un  python3.8-doc             <none>                  <none>       (no description available)
un  python3.8-gdbm            <none>                  <none>       (no description available)
un  python3.8-lib2to3         <none>                  <none>       (no description available)
ii  python3.8-minimal         3.8.10-0ubuntu1~20.04.8 amd64        Minimal subset of the Python language (version 3.8)
un  python3.8-protobuf        <none>                  <none>       (no description available)
un  python3.8-renderpm        <none>                  <none>       (no description available)
un  python3.8-reportlab-accel <none>                  <none>       (no description available)
un  python3.8-talloc          <none>                  <none>       (no description available)
un  python3.8-tk              <none>                  <none>       (no description available)
ii  python3.8-venv            3.8.10-0ubuntu1~20.04.8 amd64        Interactive high-level object-oriented language (pyvenv binary, version 3.8)
ii  python3.9                 3.9.5-3ubuntu0~20.04.1  amd64        Interactive high-level object-oriented language (version 3.9)
ii  python3.9-dbg             3.9.5-3ubuntu0~20.04.1  amd64        Debug Build of the Python Interpreter (version 3.9)
ii  python3.9-dev             3.9.5-3ubuntu0~20.04.1  amd64        Header files and a static library for Python (v3.9)
un  python3.9-distutils       <none>                  <none>       (no description available)
ii  python3.9-doc             3.9.5-3ubuntu0~20.04.1  all          Documentation for the high-level object-oriented language Python (v3.9)
ii  python3.9-examples        3.9.5-3ubuntu0~20.04.1  all          Examples for the Python language (v3.9)
ii  python3.9-full            3.9.5-3ubuntu0~20.04.1  amd64        Python Interpreter with complete class library (version 3.9)
un  python3.9-gdbm            <none>                  <none>       (no description available)
un  python3.9-lib2to3         <none>                  <none>       (no description available)
ii  python3.9-minimal         3.9.5-3ubuntu0~20.04.1  amd64        Minimal subset of the Python language (version 3.9)
un  python3.9-tk              <none>                  <none>       (no description available)
ii  python3.9-venv            3.9.5-3ubuntu0~20.04.1  amd64        Interactive high-level object-oriented language (pyvenv binary, version 3.9)

I have attempted to set some variables as shown below

cmake .. -DPython3_EXECUTABLE=/usr/bin/python3.9 \
-DPython3_INCLUDE_DIRS=/usr/include/python3.9 \
-DPython3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.9.so \
-DPython3_INCLUDE_DIR=/usr/include/python3.9 \
-DPython3_LIBRARY_DIRS=/usr/lib/x86_64-linux-gnu/libpython3.9

I have no idea how to fix this issue. All of the obvious things have been dealt with and there is an extreme dearth of information on this topic online that does more than what I’ve already done.

How do I solve this issue?

Does passing --debug-find to the cmake configure command help show why this might be problematic? Also note that some of the variables you’re setting (namely the plural ones) are output variables and should not be set in the cache.