-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
I regularly get the following error:
Error: Can't find Python executable "python", you can set the PYTHON env variable.
This is because Python on Windows by default does not place a Python executable into the PATH (and for what it’s worth, I would personally also opt out of that). Instead, Python has this great thing on Windows called the Python launcher. It’s an executable that is placed into the WINDIR directory that allows to run any installed Python version on the computer. Even more importantly, the installation of this Python launcher is the default and has been for a number of CPython releases. So for Windows, it’s a much better idea to depend on the Python launcher than on a python executable.
So I’d like to ask for a fallback in node-gyp that attempts to call py.exe -2 before ultimately failing with the above error message. So the logic would be something like this:
- Check for PYTHON environment variable; if set, use that executable
- Otherwise attempt to call the
pythonexecutable - Otherwise, if on Windows, attempt to call the
py -2executable - Otherwise show the error, and ask the user to set the PYTHON environment variable
Note that the py.exe launcher should be called with a -2 as its first argument. This ensures that a Python 2 executable is used, regardless of what has been set as the system default. Since node-gyp does not appear to support Python 3 at all yet, this would be the safest solution.
Btw. I also attempted to set the PYTHON environment variable to py -2 to make it use the Python launcher, but that didn’t work: It sadly couldn’t find the py -2 executable (i.e. it didn’t interpret the argument properly). Just using py did work, but called the wrong Python version on my system.