diff --git a/scripting/python_scripting.cpp b/scripting/python_scripting.cpp index 004c899498..e09300ea5b 100644 --- a/scripting/python_scripting.cpp +++ b/scripting/python_scripting.cpp @@ -58,24 +58,6 @@ SCRIPTING::SCRIPTING() { scriptingSetup(); -#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 - // We are going to follow the "unix" layout for the msvc/vcpkg distributions so exes in /root/bin - // And the python lib in /root/lib/python3(/Lib,/DLLs) - wxFileName pyHome; - - pyHome.Assign( Pgm().GetExecutablePath() ); - - pyHome.Normalize(); - - // MUST be called before Py_Initialize so it will to create valid default lib paths - if( !wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) ) - { - Py_SetPythonHome( pyHome.GetFullPath().c_str() ); - } -#endif - pybind11::initialize_interpreter(); // Save the current Python thread state and release the @@ -118,6 +100,25 @@ 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 + // We are going to follow the "unix" layout for the msvc/vcpkg distributions so exes in /root/bin + // And the python lib in /root/lib/python3(/Lib,/DLLs) + wxFileName pyHome; + + pyHome.Assign( Pgm().GetExecutablePath() ); + + pyHome.Normalize(); + + // MUST be called before Py_Initialize so it will to create valid default lib paths + if( !wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) ) + { + Py_SetPythonHome( pyHome.GetFullPath().c_str() ); + } + #else + // Intended for msys2 but we could probably use the msvc equivalent code too // If our python.exe (in kicad/bin) exists, force our kicad python environment wxString kipython = FindKicadFile( "python.exe" ); @@ -141,6 +142,7 @@ bool SCRIPTING::scriptingSetup() kipython << wxT( ";" ) << ppath; wxSetEnv( wxT( "PATH" ), kipython ); } + #endif #elif defined( __WXMAC__ )