-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#890 Add support for the Python launcher on Windows #894
Conversation
When looking for a Python executable on Windows, before falling back to guessing the default location or failing completely, attempt to use the Python launcher to figure out the location of the Python executable. The Python launcher is being distributed by default with Python distributions on Windows, and is placed in the %WINDIR% folder (which is in the PATH). This allows us to locate a Python installation even if it was installed without putting the python.exe executable itself into 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.
var env = extend({}, process.env) | ||
env.TERM = 'dumb' | ||
|
||
execFile('py.exe', ['-2', '-c', 'import sys; print sys.executable'], { env: env }, function (err, stdout) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you wrap this line at 80 columns?
Mostly LGTM, thanks. Can you verify that |
1292e91
to
a228a31
Compare
Updated my pull request to wrap at 80 characters; for what it’s worth, the As for the test, with my changes, |
When looking for a Python executable on Windows, before falling back to guessing the default location or failing completely, attempt to use the Python launcher to figure out the location of the Python executable. The Python launcher is being distributed by default with Python distributions on Windows, and is placed in the %WINDIR% folder (which is in the PATH). This allows us to locate a Python installation even if it was installed without putting the python.exe executable itself into 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. PR-URL: #894 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
LGTM and, seeing how there are no comments from other maintainers, I'll go ahead and land this. Thanks Patrick, merged in 3bcb172. |
Glad to see this land, thanks a lot! :) |
This is a pull request for the issue #890: “Provide fallback to Python launcher on Windows when python.exe cannot be found”.
The changes here attempt to have very little impact. The new check is just inserted between the
checkPython
call (looking for the'python'
executable) and theguessPython
call on Windows. Since the Python launcher will give an explicit Python 2 executable, it is more explicit than if we found a match usingguessPython
, so I gave the launcher solution more priority.As explained in the commit message, we cannot make a call to
py.exe -2
since that wouldn’t work withexecFile
, so I had to make an actual call to the Python launcher to get the full path of the Python executable. But if the command succeeds, then that reliably gives us a valid Python 2 executable.If there is no Python 2 version registered with the launcher, the launcher will fail when attempting to call it with
-2
. When there is no Python launcher,execFile
will fail. In both cases, the old next stepguessPython
will run.