From 44296dfea2eec51d256a65ca7d5e9fdb54d107f9 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Mon, 4 Apr 2022 22:10:59 -0400 Subject: [PATCH] Forcefully ignore PYTHONPATH env variable on Windows Fix https://gitlab.com/kicad/code/kicad/-/issues/11328 --- scripting/python_scripting.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripting/python_scripting.cpp b/scripting/python_scripting.cpp index 47956cdb0d..1541515fe8 100644 --- a/scripting/python_scripting.cpp +++ b/scripting/python_scripting.cpp @@ -110,7 +110,6 @@ if modulename in sys.modules: bool SCRIPTING::scriptingSetup() { #if defined( __WINDOWS__ ) - #ifdef _MSC_VER // Under vcpkg/msvc, we need to explicitly set the python home or else it'll start consuming // system python registry keys and the like instead of the Python distributed with KiCad. @@ -126,6 +125,14 @@ bool SCRIPTING::scriptingSetup() // MUST be called before Py_Initialize so it will to create valid default lib paths if( !wxGetEnv( wxT( "KICAD_USE_EXTERNAL_PYTHONHOME" ), nullptr ) ) { + // Global config flag to ignore PYTHONPATH & PYTHONHOME + Py_IgnoreEnvironmentFlag = 1; + + // Extra insurance to ignore PYTHONPATH and PYTHONHOME + wxSetEnv( wxT( "PYTHONPATH" ), wxEmptyString ); + wxSetEnv( wxT( "PYTHONHOME" ), wxEmptyString ); + + // Now initialize Python Home via capi Py_SetPythonHome( pyHome.GetFullPath().c_str() ); } #else