diff --git a/Modules/Python/autoload/PythonService/CMakeLists.txt b/Modules/Python/autoload/PythonService/CMakeLists.txt
index c0b5d4f8f6..15f1384ec9 100644
--- a/Modules/Python/autoload/PythonService/CMakeLists.txt
+++ b/Modules/Python/autoload/PythonService/CMakeLists.txt
@@ -1,15 +1,17 @@
 mitkFunctionCheckCompilerFlags("-Wno-cpp" CMAKE_CXX_FLAGS)
 
-mitk_create_module(PythonService
-  INCLUDE_DIRS
-    PRIVATE src/PythonService
-  DEPENDS PUBLIC MitkPython
-  PACKAGE_DEPENDS
-    PUBLIC Qt5|Widgets CTK|CTKScriptingPythonCore+CTKScriptingPythonWidgets
-    PRIVATE Python3|NumPy
-  AUTOLOAD_WITH MitkPython
-)
+if(CTKScriptingPythonCore_INCLUDE_DIRS AND CTKScriptingPythonWidgets_INCLUDE_DIRS)
+  mitk_create_module(PythonService
+    INCLUDE_DIRS
+      PRIVATE src/PythonService
+    DEPENDS PUBLIC MitkPython
+    PACKAGE_DEPENDS
+      PUBLIC Qt5|Widgets CTK|CTKScriptingPythonCore+CTKScriptingPythonWidgets
+      PRIVATE Python3|NumPy
+    AUTOLOAD_WITH MitkPython
+  )
+endif()
 
 if(TARGET ${MODULE_TARGET})
   configure_file(PythonPath.h.in "${CMAKE_CURRENT_BINARY_DIR}/PythonPath.h" @ONLY)
 endif()
diff --git a/Modules/QtPython/CMakeLists.txt b/Modules/QtPython/CMakeLists.txt
index 433b7ae4f4..c22ed5a8db 100644
--- a/Modules/QtPython/CMakeLists.txt
+++ b/Modules/QtPython/CMakeLists.txt
@@ -1,13 +1,15 @@
 if(MITK_USE_Python3)
   mitkFunctionCheckCompilerFlags("/wd4273" CMAKE_CXX_FLAGS)
 
-  mitk_create_module(
-    DEPENDS MitkCore MitkQtWidgets MitkPython
-    PACKAGE_DEPENDS
-    PUBLIC Qt5|Widgets CTK|CTKScriptingPythonCore+CTKScriptingPythonWidgets
+  if(CTKScriptingPythonCore_INCLUDE_DIRS AND CTKScriptingPythonWidgets_INCLUDE_DIRS)
+    mitk_create_module(
+      DEPENDS MitkCore MitkQtWidgets MitkPython
+      PACKAGE_DEPENDS
+      PUBLIC Qt5|Widgets CTK|CTKScriptingPythonCore+CTKScriptingPythonWidgets
     )
+  endif()
 
-  if(BUILD_TESTING)
+  if(BUILD_TESTING AND TARGET ${MODULE_TARGET})
     add_subdirectory(Testing)
   endif()
 endif()