diff --git a/lib/configure.js b/lib/configure.js index 618d96babe..a60ef139be 100644 --- a/lib/configure.js +++ b/lib/configure.js @@ -384,6 +384,7 @@ PythonFinder.prototype = { stat: fs.stat, which: which, win: win, + badVersion: '', checkPython: function checkPython () { this.log.verbose('check python', @@ -468,6 +469,9 @@ PythonFinder.prototype = { var valid = false try { valid = range.test(version) + if (!valid){ + this.badVersion = version + } } catch (e) { this.log.silly('range.test() error', e) } @@ -476,29 +480,27 @@ PythonFinder.prototype = { } else if (this.win && this.checkPythonLauncherDepth === 0) { this.checkPythonLauncher() } else { - this.failPythonVersion(version) + this.failPythonVersion() } }.bind(this)) }, failNoPython: function failNoPython () { - const err = new Error( - '\n******************************************************************\n' + - `node-gyp can't use "${this.python}",\n` + - 'It is recommended that you install python 2.7, set the PYTHON env,\n' + - 'or use the --python switch to point to a Python >= v2.6.0 & < 3.0.0.\n' + - 'For more information consult the documentation at:\n' + - 'https://github.com/nodejs/node-gyp#installation\n' + - '***********************************************************************' - ); - err.noPython = true; - this.callback(err) + if (this.badVersion != '') { + // win scenario, where we found python but invalid version. No other python versions found + this.failPythonVersion() + } + + var errmsg = + 'Can\'t find Python executable "' + this.python + + '", you can set the PYTHON env variable.' + this.callback(new Error(errmsg)) }, failPythonVersion: function failPythonVersion (badVersion) { const err = new Error( '\n******************************************************************\n' + - `Python executable "${this.python}" is v${badVersion}\n` + + `Python executable "${this.python}" is v${this.badVersion}\n` + 'this version is not supported by GYP and hence by node-gyp.\n' + 'It is recommended that you install python 2.7, set the PYTHON env,\n' + 'or use the --python switch to point to a Python >= v2.6.0 & < 3.0.0.\n' + @@ -513,6 +515,7 @@ PythonFinder.prototype = { // Called on Windows when "python" isn't available in the current $PATH. // We are going to check if "%SystemDrive%\python27\python.exe" exists. guessPython: function guessPython () { + this.checkPythonLauncherDepth += 1 this.log.verbose('could not find "' + this.python + '". guessing location') var rootDir = this.env.SystemDrive || 'C:\\' if (rootDir[rootDir.length - 1] !== '\\') {