-
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
Consider using the "py.exe" launcher to find Python 3 as well, not just for Python 2 #2130
Comments
Our automated tests pass on Python 2.7, 3.6, 3.7, and 3.8 and Python 3 Is supported on Windows. Why find Python 2 at all? It died on 1/1/2020. Let’s just find supported versions of Python and ignore EOL versions of Python. |
Hmm. Fair enough. I was thinking of posting separate fixes for (Edit: And to tell the whole story, there was a final release of Python 2.7.x in April 2020: https://www.python.org/psf/press-release/pr20191220/ https://www.python.org/doc/sunset-python-2/ but on closer reading their announcement/official position, they seem pretty clear they still want users to move away from Python 2.) |
The last three or four versions of node-gyp’s 5.x branch support Python 3. |
I only mean,
Whereas in
If this were the among the last changes to the 5.x branch, it would make that branch more python3-aware and encourage users of today's |
FWIW the I just mean (On |
There are several documented ways to get node-gyp to use the Python that you want. |
I think overall that your direction is the right one. Going forward node-gyp should use py.exe to find Python on Windows. Our custom code for this is no longer useful. |
This is a basic implementation for the 6.x branch: DeeDeeG@bb768d0 If there's something cleverer than that, it would unfortunately be a bit past my skill level in JS. I'm very much a beginner with JS. |
Some people are using python from the depot-tools, will the |
Is |
Short answer: No. It appears that properly setting up I just tried installing
Doing Neither the Apparently having the Weirdly enough, doing I wonder if it would be worth looking into this and correcting it so I note that the |
Now that node-gyp supports both Python 2 and Python 3, We don't need to explicitly try to find only Python 2. Fixes: nodejs#2130 Refs: https://docs.python.org/3/using/windows.html#launcher
Here's a proof of concept implementation against the v5.x branch: DeeDeeG@b2119e3 I have tested it, and it works as intended, but it also does appear to break the tests. |
findPython = require(./lib/find-python)
in a little standalone.js
script to test Python detection.My script ("fpy.js") (to be saved to/called from the node-gyp repo's main folder, like so: "node fpy.js".)
Verbose output (from npm or node-gyp):
Intro, Background, and the Gist of it
Hi folks, I'm wondering if the
node-gyp
team would be interested in using thepy.exe
launcher to find not only/exclusively Python 2, like it does now, but potentially Python 3 as well.(I just installed Python 3.8 from python.org, in the default install location, and
node-gyp
can't find it.py.exe
can find it, though.)Apparently, judging by the commit history, using the Python launcher strictly to find Python 2 dates back just over four years ago, to BEFORE
node-gyp
had any support for Python 3. From here: #894 (The latest published version ofnode-gyp
would have beenv3.3.1
at the time, judging by the release history: https://github.com/nodejs/node-gyp/releases?after=v3.5.0)Thus, I assume the justification for only finding Python 2 at that time would have been the following: "
node-gyp
can't work with Python 3, so finding Python 3 would be counter-productive! We must only find Python 2..." (That's no longer true, and I think it might be nice to find Python 3 with such a convenient helper/launcher likepy.exe
.)About the
py.exe
Launcher, and the installation location of Python on WindowsThe
py.exe
launcher is quite useful for finding Python. It claims to be able to find the version downloadable from python.org AND the Python downloadable from the Windows Store. Source: https://docs.python.org/3/using/windows.html#launcher) It comes with Python installers for Windows since Python 3.3.The Python situation on Windows is a little odd now, because it seems it used to be saved under something like
C:\Python[Maj[Min]\python.exe
(for example:C:\Python37
), but recent installers save to somewhere more like this:'C:\Users\[User]\AppData\Local\Programs\Python\Python38-32'
and in fact, the location can be customized during the install wizard. So it could end up anywhere,I guess.
I think the launcher might be the most reliable way to find Python on Windows these days. And in any case, it makes an excellent fallback. I only find that it is a shame that it isn't being used to find Python 3.
Indeed, going to Python.org, downloading Python 3.8.x and installing it will result in a Python installation that
node-gyp
can't find. I would like to approximatenode-gyp
's Python finding algorithm (or require itsfind-python.js
file directly), but not being able to find the default install location from python.org seems somehow not right. I didn't want to re-implement what seems like a (small) oversight in the repo I'm working on.I do think the Python from the Windows Store might end up on the path as
python
and/orpython3
, but I haven't tested or confirmed this.Suggested Solution / Notes on an Implementation
Sorry I'm not very good with JS, or I'd whip up an implementation for a PR. But I think you could really just drop the
-2
here, and update the comment above that, and that should do it.(If that solution would be sufficient, or you'd like to see it run it through the CI tests and such, I would be GLAD to whip that up as a PR.)
From a quick read of the documentation page, the
py.exe
launcher seems to prefer Python 3 over Python 2, so just dropping the-2
flag might not be appropriate for for thenode-gyp
5.x branch (which, from what I can see, generally prefers Python 2 over Python 3.)The text was updated successfully, but these errors were encountered: