From e5f1cfd2b2036a6cd53b339c5e6a1de736d1f82f Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Mon, 13 Nov 2023 23:08:53 -0500 Subject: [PATCH] Set PYTHONPATH internally for macOS run from build dir --- cmake/config.h.cmake | 2 ++ scripting/python_scripting.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index 8bcd3a1ca8..d6c56cdfe8 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -91,6 +91,8 @@ /// Allows scripts install directory to be referenced by the program code. #define PYTHON_DEST "@PYTHON_DEST@" +#define PYTHON_SITE_PACKAGE_PATH "@PYTHON_SITE_PACKAGE_PATH@" + /// Allows scripts install directory to be referenced by the program code. #define KICAD_DATA "@KICAD_DATA@" diff --git a/scripting/python_scripting.cpp b/scripting/python_scripting.cpp index d678d1d588..4d0e38065c 100644 --- a/scripting/python_scripting.cpp +++ b/scripting/python_scripting.cpp @@ -281,6 +281,13 @@ bool SCRIPTING::scriptingSetup() pypath = wxString( wxGetenv( wxT( "PYTHONPATH" ) ) ) + wxT( ":" ) + pypath; } + // Hack for run from build dir option + if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) ) + { + pypath = wxString( wxT( PYTHON_SITE_PACKAGE_PATH ) ) + wxT( "/../:" ) + + wxT( PYTHON_SITE_PACKAGE_PATH ) + wxT( ":" ) + wxT( PYTHON_DEST ); + } + // set $PYTHONPATH wxSetEnv( wxT( "PYTHONPATH" ), pypath );