From f649c821aa153a40b0219f758086abad7314a466 Mon Sep 17 00:00:00 2001
From: jmcarcell <jmcarcell@users.noreply.github.com>
Date: Wed, 24 Apr 2024 21:29:09 +0200
Subject: [PATCH] Don't use the deprecated PySys_SetArgv

---
 .../src/Services/PythonScriptingSvc.cpp       | 30 +++++++------------
 1 file changed, 11 insertions(+), 19 deletions(-)

diff --git a/GaudiPython/src/Services/PythonScriptingSvc.cpp b/GaudiPython/src/Services/PythonScriptingSvc.cpp
index a97357976c..504e84b276 100644
--- a/GaudiPython/src/Services/PythonScriptingSvc.cpp
+++ b/GaudiPython/src/Services/PythonScriptingSvc.cpp
@@ -9,17 +9,7 @@
 * or submit itself to any jurisdiction.                                             *
 \***********************************************************************************/
 #include "Python.h"
-
-// Python 3 compatibility
-#if PY_MAJOR_VERSION >= 3
-
-#  define PySys_SetArgv_Char_t wchar_t
-
-#else
-
-#  define PySys_SetArgv_Char_t char
-
-#endif
+#include <cpython/initconfig.h>
 
 // Include Files
 #include "GaudiKernel/ISvcLocator.h"
@@ -75,17 +65,19 @@ StatusCode PythonScriptingSvc::initialize()
     }
   }
 
-  // Python 3 compatibility
-#if PY_MAJOR_VERSION >= 3
   wchar_t* progName[] = { const_cast<wchar_t*>( L"GaudiPython" ) };
-#else
-  char* progName[] = { const_cast<char*>( "GaudiPython" ) };
-#endif
 
-  // Initialize the Python interpreter.  Required.
-  Py_Initialize();
+  PyStatus status;
+
+  PyConfig config;
+  PyConfig_InitPythonConfig( &config );
+
+  status = PyConfig_SetString( &config, &config.program_name, progName[0] );
   // Set argv for Tkinter (needs program name)
-  PySys_SetArgv( 1, progName );
+  status = PyConfig_SetArgv( &config, 1, progName );
+  status = Py_InitializeFromConfig( &config );
+  PyConfig_Clear( &config );
+
   // Get the Python version
   std::string fullversion = Py_GetVersion();
   std::string version( fullversion, 0, fullversion.find_first_of( ' ' ) );
-- 
GitLab