From 8023c7a79478e2ee0955a6c1383a93a3fb1ca08e Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 14 Nov 2016 08:35:12 +0100 Subject: [PATCH] Pcbnew: fix outdated environment vars settings for Kicad python on Windows (from master branch): On Windows, previously, Pcbnew try to set env vars PYTHONPATH, if /bin/python27_us folder is found. Now, if python.exe is found in kicad bin folder (therefore if our python executable and libs are installed in Kicad), PYTHONPATH and PYTHONHOME are set to an empty string. ( the default python path work fine with our standard python install ) --- pcbnew/pcbnew.cpp | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 0abbd00038..ddbdd03d81 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -205,40 +205,29 @@ static bool scriptingSetup() { wxString path_frag; -#if defined( __MINGW32__ ) - // force python environment under Windows: - const wxString python_us( wxT( "python27_us" ) ); +#if defined( __WINDOWS__ ) + // If our python.exe (in kicad/bin) exists, force our kicad python environment + wxString kipython = FindKicadFile( "python.exe" ); - // Build our python path inside kicad - wxString kipython = FindKicadFile( python_us + wxT( "/python.exe" ) ); - - //we need only the path: - wxFileName fn( kipython ); + // we need only the path: + wxFileName fn( kipython ); kipython = fn.GetPath(); // If our python install is existing inside kicad, use it + // Note: this is usefull only when an other python version is installed if( wxDirExists( kipython ) ) { + // clear any PYTHONPATH and PYTHONHOME env var definition: the default + // values work fine inside Kicad: + wxSetEnv( wxT( "PYTHONPATH" ), wxEmptyString ); + wxSetEnv( wxT( "PYTHONHOME" ), wxEmptyString ); + + // Add our python executable path in first position: wxString ppath; + wxGetEnv( wxT( "PATH" ), &ppath ); - if( !wxGetEnv( wxT( "PYTHONPATH" ), &ppath ) || !ppath.Contains( python_us ) ) - { - ppath << kipython << wxT( "/pylib;" ); - ppath << kipython << wxT( "/lib;" ); - ppath << kipython << wxT( "/dll" ); - wxSetEnv( wxT( "PYTHONPATH" ), ppath ); - // DBG( std::cout << "set PYTHONPATH to " << TO_UTF8( ppath ) << "\n"; ) - - // Add python executable path: - wxGetEnv( wxT( "PATH" ), &ppath ); - - if( !ppath.Contains( python_us ) ) - { - kipython << wxT( ";" ) << ppath; - wxSetEnv( wxT( "PATH" ), kipython ); - // DBG( std::cout << "set PATH to " << TO_UTF8( kipython ) << "\n"; ) - } - } + kipython << wxT( ";" ) << ppath; + wxSetEnv( wxT( "PATH" ), kipython ); } // TODO: make this path definable by the user, and set more than one path