diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 8979cb2589..5f6189e67b 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * @@ -203,40 +203,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 ); } // wizard plugins are stored in ../share/kicad/scripting/plugins. @@ -298,7 +287,7 @@ static bool scriptingSetup() // determined by the python pcbnew.py initialisation code. if( !pcbnewInitPythonScripting( TO_UTF8( path_frag ) ) ) { - wxLogError( wxT( "pcbnewInitPythonScripting() failed." ) ); + wxLogError( "pcbnewInitPythonScripting() failed." ); return false; }