diff --git a/Core/Tools/src/PyGenTools.cpp b/Core/Tools/src/PyGenTools.cpp
index 2a3c9aebbef350c8abafde7fac9dc8e235a6eec1..271402ce9ccb8c914b34e79c6809f71f0b63149a 100644
--- a/Core/Tools/src/PyGenTools.cpp
+++ b/Core/Tools/src/PyGenTools.cpp
@@ -12,6 +12,7 @@
 #include "MultiLayer.h"
 #include "PyGenTools.h"
 #include "Simulation.h"
+#include "BAPython.h"
 
 std::string PyGenTools::genPyScript(Simulation *simulation)
 {
@@ -97,7 +98,7 @@ bool PyGenTools::testPyScript(Simulation *simulation)
 //                simulation->getIntensityData());
 //    boost::scoped_ptr<const OutputData<double> > simulated_data(
 //                    pSimulation->getIntensityData());
-    std::string command = "python PythonScript.py";
+    std::string command = std::string(BORNAGAIN_PYTHON_EXE ) + " PythonScript.py";
     int return_code = std::system(command.c_str());
     (void)return_code;
     if (std::remove("PythonScript.py") != 0) {
diff --git a/cmake/modules/SearchInstalledSoftware.cmake b/cmake/modules/SearchInstalledSoftware.cmake
index 6a3c6deaf70f459dde2d7153adc6c9ced1521019..44089e3834352eaf3765b9766c28819ed67f60e6 100644
--- a/cmake/modules/SearchInstalledSoftware.cmake
+++ b/cmake/modules/SearchInstalledSoftware.cmake
@@ -17,7 +17,7 @@ find_package(FFTW REQUIRED)
 
 # --- BOOST ---
 set(Boost_USE_STATIC_LIBS OFF)
-set(Boost_USE_MULTITHREADED ON) 
+set(Boost_USE_MULTITHREADED ON)
 set(Boost_USE_STATIC_RUNTIME OFF)
 add_definitions(-DBOOST_ALL_DYN_LINK) # line is needed for MSVC
 #add_definitions(-DBOOST_LIB_DIAGNOSTIC) # shows during compilation auto-linked libraries
@@ -72,6 +72,8 @@ if(BORNAGAIN_PYTHON OR BORNAGAIN_GUI)
 
     ValidatePythonIntstallation()
 
+    configure_file("${CMAKE_SOURCE_DIR}/cmake/scripts/BAPython.h.in" "${CMAKE_BINARY_DIR}/BAPython.h" @ONLY)
+
     if(NOT PYTHONLIBS_FOUND)
         message(FATAL_ERROR "No Python library has been found")
     endif()
diff --git a/cmake/scripts/BAPython.h.in b/cmake/scripts/BAPython.h.in
new file mode 100644
index 0000000000000000000000000000000000000000..5649f9e4181a7042457a4a0b345cae2918d14799
--- /dev/null
+++ b/cmake/scripts/BAPython.h.in
@@ -0,0 +1,23 @@
+// ************************************************************************** //
+//
+//  BornAgain: simulate and fit scattering at grazing incidence
+//
+//! @file      Tools/inc/BAPython.h
+//! @brief     Defines configuration variables
+//!
+//! @homepage  http://apps.jcns.fz-juelich.de/BornAgain
+//! @license   GNU General Public License v3 or higher (see COPYING)
+//! @copyright Forschungszentrum Jülich GmbH 2013
+//! @authors   Scientific Computing Group at MLZ Garching
+//! @authors   C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke
+//
+// ************************************************************************** //
+
+#ifndef BAPYTHON_H
+#define BAPYTHON_H
+
+/* Configuration file will be automatically regenerated by CMake */
+
+#define BORNAGAIN_PYTHON_EXE "@PYTHON_EXECUTABLE@"
+
+#endif