nodejs/node-gyp

Support for Python 3

cclauss opened this issue Β· 76 comments

See #1150, #1335, #1336, and https://travis-ci.com/nodejs/node/builds/79706150 (nodejs/node#21942)

  • Node Version:
  • Platform:
  • Compiler:
  • Module:
Verbose output (from npm or node-gyp):

Historically the blocker to this has been the gyp dependency and normally changes should be upstreamed there unless we're planning on forking gyp in which case we would want our own gyp project so that we can share the changes with the main Node.js project.

cc @nodejs/gyp

I cannot successfully install Angular on my mac. I keep getting gyp error and when I look at gyp-mac-tool it says:
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb which failed Error: not found: python2
gyp verb which failed at getNotFoundError (/Users/thackerfam/AngularProj/angular-cli/node_modules/which/which.js:13:12)

I have had python 3 installed forever and do not want python 2 as it can cause havoc to have both installed as they are not compatible with one another. If this is the reason for my inability to use Angular, what should I do?

On your Mac, what happens when you do:

  • python2 --version
  • /usr/bin/python --version
  • /usr/bin/python2 --version
  • /usr/bin/python2.7 --version

I would highly recommend Homebrew as essential if you are doing real development on a Mac.

Brew allows you to easily install both Python 2 and Python3 with: brew install python python@2

A few Python 2 issues on gyp:

$ python2 -m flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics

./gyptest.py:61:47: F821 undefined name 'opts'
    extra_path = [os.path.abspath(p) for p in opts.path]  # <-- 'opts' should be changed to 'args'
                                              ^
./pylib/gyp/generator/make.py:1637:50: F821 undefined name 'target'
      print "WARNING: no output for", self.type, target  # <-- 'target' should be changes to 'self.target'
                                                 ^

I have faced and fixed this issue relates node-sass and python error.Try installing latest angular cli command with the steps below

Set the system variable path as well:
C:\Users\windowsusername\AppData\Roaming\npm

C:\Users\windowsusername\AppData\Roaming\npm\node_modules@angular\cli\bin;

C:\Program Files\nodejs;

Then start using angular cli command prompt using:
angular client project folder path>npm install -g @latest

angular client project folder path>npm install -g node-gyp

It's a bit embraced that the original gyp project relies on python 2, and after couple of years, the patch is getting too big so that no people is dare to review and merge it. Need to give the gyp community more feedback to move this forward.

Is there any interest in this? Python 2 is starting to get removed from distributions at this point.

Python 2 is starting to get removed from distributions at this point.

Correct e.g. brew is now installing/upgrading to Python 3 by default.

The following just worked for me as I already had a python2.7 executable installed via brew:

npm config set python python2.7

However, if you don't have a python2.7 executable, I suspect you can do something like:

brew install python@2
# follow the instructions printed after installing `python@2` to get python 2 on your PATH 
# e.g. echo 'export PATH="/usr/local/opt/python@2/bin:$PATH"' >> ~/.bashrc
npm config set python python2.7

Tim's method should go in the README. I use ZSH and there was a message mentioned Xcode when I installed Python 2 so my process was as follows:

xcode-select --install

brew install python@2
echo 'export PATH="/usr/local/opt/python@2/bin:$PATH"' >> ~/.zshrc
npm config set python python2.7

For some reason, npm config set python python2.7 stopped working for me. Even after setting it, I get the error that node-gyp is trying to run python 3.6

What does python2.7 --version return on your machine?

> python2.7 --version
Python 2.7.14

Here is the full error

^_^ > apm install      
Installing modules βœ—
> node-pty@0.7.4 install /Users/samuel/.atom/packages/script-runner/node_modules/node-pty
> node scripts/install.js

script-runner@3.0.0 /Users/samuel/.atom/packages/script-runner
β”œβ”€β”€ etch@0.14.0 
β”œβ”€β”€ resize-observer-polyfill@1.5.0 
β”œβ”€β”¬ shell-environment@0.3.1 
β”‚ └─┬ os-locale@2.1.0 
β”‚   β”œβ”€β”¬ execa@0.7.0 
β”‚   β”‚ β”œβ”€β”¬ cross-spawn@5.1.0 
β”‚   β”‚ β”‚ β”œβ”€β”¬ lru-cache@4.1.2 
β”‚   β”‚ β”‚ β”‚ β”œβ”€β”€ pseudomap@1.0.2 
β”‚   β”‚ β”‚ β”‚ └── yallist@2.1.2 
β”‚   β”‚ β”‚ β”œβ”€β”¬ shebang-command@1.2.0 
β”‚   β”‚ β”‚ β”‚ └── shebang-regex@1.0.0 
β”‚   β”‚ β”‚ └─┬ which@1.3.0 
β”‚   β”‚ β”‚   └── isexe@2.0.0 
β”‚   β”‚ β”œβ”€β”€ get-stream@3.0.0 
β”‚   β”‚ β”œβ”€β”¬ npm-run-path@2.0.2 
β”‚   β”‚ β”‚ └── path-key@2.0.1 
β”‚   β”‚ β”œβ”€β”€ p-finally@1.0.0 
β”‚   β”‚ β”œβ”€β”€ signal-exit@3.0.2 
β”‚   β”‚ └── strip-eof@1.0.0 
β”‚   β”œβ”€β”¬ lcid@1.0.0 
β”‚   β”‚ └── invert-kv@1.0.0 
β”‚   └─┬ mem@1.1.0 
β”‚     └── mimic-fn@1.2.0 
β”œβ”€β”€ shellwords@0.1.1 
β”œβ”€β”¬ temp-write@3.4.0 
β”‚ β”œβ”€β”€ graceful-fs@4.1.11 
β”‚ β”œβ”€β”€ is-stream@1.1.0 
β”‚ β”œβ”€β”€ make-dir@1.2.0 
β”‚ β”œβ”€β”€ pify@3.0.0 
β”‚ β”œβ”€β”€ temp-dir@1.0.0 
β”‚ └── uuid@3.2.1 
└── xterm@3.3.0 


gyp ERR! configure error 
gyp ERR! stack Error: Python executable "/Applications/Atom.app/Contents/Resources/app/apm/bin/python-interceptor.sh" is v3.6.4, which is not supported by gyp.
gyp ERR! stack You can pass the --python switch to point to Python >= v2.5.0 & < 3.0.0.
gyp ERR! stack     at failPythonVersion (/Applications/Atom.app/Contents/Resources/app/apm/node_modules/node-gyp/lib/configure.js:454:14)
gyp ERR! stack     at /Applications/Atom.app/Contents/Resources/app/apm/node_modules/node-gyp/lib/configure.js:443:9
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:197:7)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at maybeClose (internal/child_process.js:877:16)
gyp ERR! stack     at Socket.<anonymous> (internal/child_process.js:334:11)
gyp ERR! stack     at emitOne (events.js:96:13)
gyp ERR! stack     at Socket.emit (events.js:188:7)
gyp ERR! stack     at Pipe._handle.close [as _onclose] (net.js:498:12)
gyp ERR! System Darwin 17.5.0
gyp ERR! command "/Applications/Atom.app/Contents/Resources/app/apm/bin/node" "/Applications/Atom.app/Contents/Resources/app/apm/node_modules/.bin/node-gyp" "rebuild"
gyp ERR! cwd /Users/samuel/.atom/packages/script-runner/node_modules/node-pty
gyp ERR! node -v v6.9.5
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok 
npm ERR! Darwin 17.5.0
npm ERR! argv "/Applications/Atom.app/Contents/Resources/app/apm/bin/node" "/Applications/Atom.app/Contents/Resources/app/apm/node_modules/npm/bin/npm-cli.js" "--globalconfig" "/Users/samuel/.atom/.apm/.apmrc" "--userconfig" "/Users/samuel/.atom/.apmrc" "install" "--runtime=electron" "--target=1.7.11" "--arch=x64"
npm ERR! node v6.9.5
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE

npm ERR! node-pty@0.7.4 install: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-pty@0.7.4 install script 'node scripts/install.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the node-pty package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node scripts/install.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs node-pty
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls node-pty
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/samuel/.atom/packages/script-runner/npm-debug.log

Here is my config

 > apm config list
; cli configs
globalconfig = "/Users/samuel/.atom/.apm/.apmrc"
user-agent = "npm/3.10.10 node/v6.9.5 darwin x64"
userconfig = "/Users/samuel/.atom/.apmrc"

; environment configs
node-gyp = "/Applications/Atom.app/Contents/Resources/app/apm/bin/../node_modules/.bin/node-gyp"
python = "/Applications/Atom.app/Contents/Resources/app/apm/bin/python-interceptor.sh"

; userconfig /Users/samuel/.atom/.apmrc

; globalconfig /Users/samuel/.atom/.apm/.apmrc
cache = "/Users/samuel/.atom/.apm"
progress = false

; node bin location = /Applications/Atom.app/Contents/Resources/app/apm/bin/node
; cwd = /Users/samuel/.atom/packages/script-runner
; HOME = /Users/samuel/.atom/.node-gyp
; "npm config ls -l" to show all defaults.

^_^ > npm config list
; cli configs
user-agent = "npm/3.10.10 node/v8.10.0 darwin x64"

; userconfig /Users/samuel/.npmrc
init.author.email = "samuel.williams@oriontransfer.co.nz"
init.author.name = "Samuel Williams"
init.author.url = "http://www.codeotaku.com"
python = "python2.7"

; node bin location = /opt/local/bin/node
; cwd = /Users/samuel/.atom/packages/script-runner
; HOME = /Users/samuel
; "npm config ls -l" to show all defaults.

Hmm, I'm sure I also had apm config set python=python2.7. Maybe that's why it's not working.

That's odd, maybe it's a bug in apm.

> apm config set python python2.7
> apm config list                
; cli configs
globalconfig = "/Users/samuel/.atom/.apm/.apmrc"
user-agent = "npm/3.10.10 node/v6.9.5 darwin x64"
userconfig = "/Users/samuel/.atom/.apmrc"

; environment configs
node-gyp = "/Applications/Atom.app/Contents/Resources/app/apm/bin/../node_modules/.bin/node-gyp"
python = "/Applications/Atom.app/Contents/Resources/app/apm/bin/python-interceptor.sh"

; userconfig /Users/samuel/.atom/.apmrc

; globalconfig /Users/samuel/.atom/.apm/.apmrc
cache = "/Users/samuel/.atom/.apm"
progress = false

; node bin location = /Applications/Atom.app/Contents/Resources/app/apm/bin/node
; cwd = /Users/samuel/.atom/packages/script-runner
; HOME = /Users/samuel/.atom/.node-gyp
; "npm config ls -l" to show all defaults.

Even thought I set it, it's not changed in the config!?

@ioquatix what does "apm config get" show?

[raijin@ishtar][~]%apm config get
; cli configs
globalconfig = "/home/raijin/.atom/.apm/.apmrc"
user-agent = "npm/3.10.10 node/v6.9.5 linux x64"
userconfig = "/home/raijin/.atom/.apmrc"

; environment configs
node-gyp = "/usr/share/atom/resources/app/apm/bin/../node_modules/.bin/node-gyp"

; userconfig /home/raijin/.atom/.apmrc
python = "python2.7"

; globalconfig /home/raijin/.atom/.apm/.apmrc
cache = "/home/raijin/.atom/.apm"
progress = false

; node bin location = /usr/share/atom/resources/app/apm/bin/node
; cwd = /home/raijin
; HOME = /home/raijin/.atom/.node-gyp
; "npm config ls -l" to show all defaults.
koyoko% apm config get
; cli configs
globalconfig = "/home/samuel/.atom/.apm/.apmrc"
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.0.0 node/v10.0.0 linux x64"
userconfig = "/home/samuel/.atom/.apmrc"

; environment configs
python = "/usr/lib/node_modules/atom-package-manager/bin/python-interceptor.sh"

; project config /home/samuel/.npmrc
strict-ssl = true

; globalconfig /home/samuel/.atom/.apm/.apmrc
cache = "/home/samuel/.atom/.apm"
progress = false

; node bin location = /usr/bin/node
; cwd = /home/samuel
; HOME = /home/samuel/.atom/.node-gyp
; "npm config ls -l" to show all defaults.

koyoko% apm config set python foo
koyoko% apm config get           
; cli configs
globalconfig = "/home/samuel/.atom/.apm/.apmrc"
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.0.0 node/v10.0.0 linux x64"
userconfig = "/home/samuel/.atom/.apmrc"

; environment configs
python = "/usr/lib/node_modules/atom-package-manager/bin/python-interceptor.sh"

; project config /home/samuel/.npmrc
strict-ssl = true

; userconfig /home/samuel/.atom/.apmrc

; globalconfig /home/samuel/.atom/.apm/.apmrc
cache = "/home/samuel/.atom/.apm"
progress = false

; node bin location = /usr/bin/node
; cwd = /home/samuel
; HOME = /home/samuel/.atom/.node-gyp
; "npm config ls -l" to show all defaults.

It's one thing to retain support for Python 2 (though many projects are dropping it altogether). It's another thing entirely to _not _ support Python 3. Please consider this. Python 3 is a decade old, after all... πŸ˜„

star this https://bugs.chromium.org/p/gyp/issues/detail?id=36 to help resolve this issue

starred, not sure why 10 years have passed and we are still dealing with this!

GYP is dead. Google moved on to GN.

What is GN?

Yea but this thread https://groups.google.com/forum/#!topic/gyp-developer/U66xtisrYRM says it's just a matter of Dirk landing and reviewing the patch.

My question is this: why can't we just fork gyp and add the patch and go with that?

There is no reason why not. That is the way of open source. If no maintainer steps forward with a cogent plan that fits your needs, you can always hit the fork button.

Perhaps @refack can help to keep things progressing on this repo.

Is there any movement on node-gyp compatible with Python 3.6+ as it does make any sense to downgrade to Python 2.7 on my system? Is the issue with the gyp src? If this is the case, what does one need to do resolve the issue?

Let's contribute to the deno project.

https://github.com/ry/deno

They too seem to be focused on legacy Python at a time when EOL is only about 500 days away.

Do the math dude! http://pythonclock.org

On 2018-08-19 there will be 500 days until Python 2 end of life.

https://github.com/cclauss/Ten-lines-or-less/blob/master/daze_left.py

...I forgot what year it was.

Should it use six to keep compatibility?

Is there any movement on node-gyp compatible with Python 3.6+ as it does make any sense to downgrade to Python 2.7 on my system? Is the issue with the gyp src? If this is the case, what does one need to do resolve the issue?

Did we get an answer on that? Please let us know what the underlying issue is, so that we can work on allowing having Python 3 used. We do not have to remove support for Python 2, but we should definitely have support for Python 3.

So #1335 landed. Now we need to fix the python detection logic in the JS part

Any action here: with nodejs 10.13LTS you still ned python2:

C:\Users\morten.sensio\AppData\Roaming\npm\node_modules\appium\node_modules\heapdump>if not defined npm_config_node_gyp
(node "C:\dist\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp
.js" rebuild )  else (node "C:\dist\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Command failed: D:\python\Python371\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];

if you are mainly on python2.7.x or higher most frequent python3 features have been backported like:

D:\python\Python371\python.EXE -c "import sys; print('%s.%s.%s' % sys.version_info[:3])"
3.7.1
D:\python\Python2715\python.EXE -c "import sys; print('%s.%s.%s' % sys.version_info[:3])"
2.7.15

FYI, Python 3 support is committed on gyp repository:
https://github.com/chromium/gyp/commits/master

@methane @dpranke On the https://github.com/chromium/gyp repo, flake8 still spots at least two Python 3 syntax errors E999 and 9 instances of F821 undefined names including several issues for Python builtins cmp() and buffer() that were removed in Python 3.
https://travis-ci.org/chromium/gyp/jobs/464221586#L473

Well, I won't swear that the Python3 support is perfect but it should be pretty close once a couple more minor patches land, at least.

Really nice work! chromium/gyp has done it... https://travis-ci.org/chromium/gyp/builds/466532175

Where are we on this issue folks?? PRs are no longer getting reviewed? How do we make progress once again?

Not sure I see I fix above or not. I have this issue opened where I can't install the module on osx ethereumjs/helpeth#25 should node-gyp be updated in the project?

rvagg commented

Discussing this and related issues nodejs/TSC#642, if anyone here is passionate about python & node then you might want to join in on a working group or strategic initiative we may start to figure out an approach to moving ourselves beyond this mess. node-gyp is such a critical piece of Node ecosystem infrastructure that touching it carries a lot of risk, hence some of the hesitancy moving forward too fast on any of this. It's going to be extremely sensitive to breakage and edge cases and this repo already gets more support issues than we can handle.

I am happy to remain engaged in the effort but would appreciate help. Where there are effective JavaScript solutions, we should transition to those.

node-gyp is such a critical piece of Node ecosystem infrastructure

One year from now, there will be no more updates -- not even security updates -- to legacy Python. The Node ecosystem infrastructure is too strategic and widely used to be based on unsupported code so by 1/1/2020, we really want no Python 2 in this codebase. If there are acceptable JavaScript substitutes then we should switch to them but this codebase really should not rely on Python 2. The sunsetting of Python 2 has already been delayed five years so that community is now quite emphatic on the no more updates policy. This is fair given that Python 3 predates Node.js.

I think you're 10 years too late to be talking about β€œmoving forward too fast”.

Over a year ago #1336 attempted to directly link pull requests to automated tests so that contributors and reviewers had βœ… or ❌ to give them a sanity check on PRs. Can we please get something similar working on this repo?

Some tactical steps (going down a path of porting what we have, instead of replacing):

One important way that everyone can help is to review the above PRs.

Any progress on these issues?? I opened this issue more than a year ago and in less than one year, support for Python 2 expires.

https://pythonclock.org Python 2.7 will reach end-of-life after December 31, 2019.

python2.7 is not installed on Debian 9 Stretch by default it seems, which means unless sysadmins install it explicitly, Node.js projects involving node-gyp somewhere in their dependencies currently fail to install properly.

We are transitioning to not supporting python2 anymore. This is the only blocker stopping us from doing this. Im really looking forward to when node-gyp can use python3

Where there are effective JavaScript solutions, we should transition to those.

@cclauss I prefer a pure JavaScript solution, and I would like to help. Is there already an issue discussing the possibility of switching to pure-JavaScript compiling solutions? I guess it would be off-topic to discuss it here.

@cclauss do you think this is being progressed under nodejs/TSC#642 or is there something we need to action in this issue?

@mhdawson I would love to see progress on #1336 ... It seems so simple but it has been a loong time.

#1337 (comment) is still our running list... Some progress has been made but still several items are open awaiting review. More active reviewers would be a beautiful thing. Also, we are going to need build machines to have Python 3 loaded on them in addition to Python 2 so that we can be sure that tests pass on both versions of Python.

I don't quite understand the need for Python 2.7 (also it is clocking down less than a year).
Wouldn't it be possible to write the python code so that a python 3 interpreter is happy? I've written such code in the past which would run on both py2 and py3. And maybe this could be used for some simple use cases...

@vogt31337 It is a BIG codebase. See https://github.com/refack/GYP to get a sense of how many changes were required to get it compatible with Python 3.

@vogt31337 It is a BIG codebase. See https://github.com/refack/GYP to get a sense of how many changes were required to get it compatible with Python 3.

I hope we can finally do away with Python 2, I am sure node-gyp is for many the last blocker remaining.

Although I do not personally quite understand why node.js really needs this wrapper around the build tool instead of letting module developers take care of it (you have to install native libraries for many native modules anyway, so its not like node-gyp and gyp itself solve the "per-library requirement" problem), but that's a different story.

Hi. Homebrew maintainer here.

I just wanted to notify the node maintainers that we started the discussions around the Python 2 removal from the Homebrew package manager. Node is one of the last β€œbig” packages that does not support Python 3. I would like to avoid a situation where we would need to remove node from brew. Node is in our top 3 of installed packages, with more than 4 million install events per year.

Right now we are just gathering opinions https://discourse.brew.sh/t/python-2-eol-2020/4647
No decision has been taken yet.

Options go from plain removal, additional grace period of a few months, moving node to an external tap outside of our org, or any other idea that will come up in the next weeks.

rvagg commented

Thanks @iMichka, we have a team that's trying hard to bring Node up to Python 3 support. Unfortunately we missed out on the Node 12.0.0 window but we're acutely aware of the time pressures of continuing our Python 2 requirement. @cclauss @refack @thefourtheye and others are working hard addressing our sprawling use of Python. I'm not sure we have a firm timeframe but this is a well known problem and we all feel the pressure (and bump up against it regularly!). I would hope that we can have it resolved within the next couple of months but I can't speak with any authority on that.

moving node to an external tap outside of our org

@iMichka Given that soon-to-be-released Node.js 12 will still require legacy Python, can you please provide us with a sense of the degree of difficulty required to set up and maintain an external tap? Are there other examples of external taps that your team considers to be well set up and maintained?

I'm a homebrew maintainer, and I also maintain an external tap with bottles from private CI machines. It's super easy to make a tap and push formula updates to it. In my opinion, the bulk of the work is in getting bottles to build successfully and fixing inter-package compatibility problems. One hopefully useful option will be building homebrew bottles with something like Azure pipelines, as discussed in the following post:

@cclauss to bounce back on what @scpeters was saying, setting up and maintaining a tap is pretty straight forward and easy.

The bottle part is a little trickier but I'm close to a fully working solution that would make it much easier for tap maintainer to distribute bottles for their taps.

I'll post here when it's ready.

I'm commented in several other thread that one limiting factor for getting full Python3 compatibility for GYP3, and hence node-gyp, is having a proper CI testing setup. I've submitted nodejs/build#1789 as for me setting up CI testing on the Node.js cluster is the lowest hanging fruit.

a sense of the degree of difficulty required to **set up and maintain an _external

It is doable. The issue will be more about visibility. More than 4 million install events in a year through homebrew will mean that we need to communicate to all these people about the node removal from homebrew-core, and give instructions on how to tap the new node tap. All the install scripts from the whole industry will probably need an updated too. There will be no automatic redirection to an external tap.

I do not want to pollute this thread more with homebrew discussions though. We are not the only ones to ship node, so the issue is more global than this. Not sure this issue is the best place to discuss all this. We have not taken any decision right now, my initial message was more a gentle nudge to warn you that bigger changes may come :)

We are not the only ones to ship node, so the issue is more global than this.

Indeed, it's much more global than this. There has been discussion on removing python2 from openSUSE Tumbleweed distribution at beginning of next year. For those that don't know, Tumbleweed is the rolling release distribution of openSUSE project.

https://lists.opensuse.org/opensuse-factory/2019-04/msg00229.html

on the bright fresh chilly morning of 2020-01-02 we are going to remove python2 package (that's python 2.7.* interpreter) from Factory.

Is this in progress?

@mingrammer #1723 (comment) lists some current Python 3 incompatibilities if you have some time to work on this. We also created GYP3 nodejs/node#26620

Would it be possible to edit the opening post in this thread with a general summary of the situation with regards to the move to Python 3 due to the Python 2 EOL and drop from Brew/macOS/Linux distros? It'd be great if that could then be kept up to date so the average user can easily see an overview of the current situation and the plan going forward :)

Closing this PR as GYP seems to be Python 3 compatible:

If you find any Python 3 incompatibles in this code, please open an issue.

NOTE: nodejs/node is not yet compatible with Python 3 but an effort is ongoing there.

Python 2 is starting to get removed from distributions at this point.

Correct e.g. brew is now installing/upgrading to Python 3 by default.

The following just worked for me as I already had a python2.7 executable installed via brew:

npm config set python python2.7

However, if you don't have a python2.7 executable, I suspect you can do something like:

brew install python@2
# follow the instructions printed after installing `python@2` to get python 2 on your PATH 
# e.g. echo 'export PATH="/usr/local/opt/python@2/bin:$PATH"' >> ~/.bashrc
npm config set python python2.7

Thanks! this resolves my issues

I'm using Node.js v 12.18.2 and Python v3.8.1 on windows 10 and when I tried to run npm install I got this error:

gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Program Files (x86)\Python\Python\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                       ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:303:12)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\x199377\\AppData\\Local\\Programs\\Git\\react-whiteapp\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd C:\Users\x199377\AppData\Local\Programs\Git\react-whiteapp\node_modules\node-sass
gyp ERR! node -v v12.18.2
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1

gyp ERR! node-gyp -v v3.8.0

Please upgrade node-gyp to v7 https://github.com/nodejs/node-gyp/releases

@slim-hmidi If you want to use Python 3 you'll have to take up with node-sass as they're still depending on node-gyp ^3.8.0: https://github.com/sass/node-sass/blob/e1fc1580c2e979113c95850b8ae5d83845063ca5/package.json#L67

node-gyp added Python 3 support in the 5.x and later releases.

@richardlau I installed python v2.7.16 but still the same problem.

If you have the same problem it means that node-gyp is still trying to use Python 3. Maybe try setting the PYTHON environment variable to point to your installed Python 2?

I uninstalled python 3 and python 2.7.16 and I'm reinstalling python 2.7.16 again and I will try again.

@richardlau it works now. thanks