diff --git a/lib/configure.js b/lib/configure.js index 4e0652961e..22251ba725 100644 --- a/lib/configure.js +++ b/lib/configure.js @@ -325,7 +325,7 @@ function findPython (python, callback) { return checkPython() } if (win) { - guessPython() + checkPythonLauncher() } else { failNoPython() } @@ -340,6 +340,31 @@ function findPython (python, callback) { }) } + // Distributions of Python on Windows by default install with the "py.exe" + // Python launcher which is more likely to exist than the Python executable + // being in the $PATH. + // Because the Python launcher supports all versions of Python, we have to + // explicitly request a Python 2 version. This is done by supplying "-2" as + // the first command line argument. Since "py.exe -2" would be an invalid + // executable for "execFile", we have to use the launcher to figure out + // where the actual "python.exe" executable is located. + function checkPythonLauncher () { + log.verbose('could not find "' + python + '". checking python launcher') + var env = extend({}, process.env) + env.TERM = 'dumb' + + var launcherArgs = ['-2', '-c', 'import sys; print sys.executable'] + execFile('py.exe', launcherArgs, { env: env }, function (err, stdout) { + if (err) { + guessPython() + return + } + python = stdout.trim() + log.verbose('check python launcher', 'python executable found: %j', python) + checkPythonVersion() + }) + } + // Called on Windows when "python" isn't available in the current $PATH. // We're gonna check if "%SystemDrive%\python27\python.exe" exists. function guessPython () {