question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

node-gyp fails build because it can't find python2

See original GitHub issue
  • 5.22.1:
  • mac:

I have an electron project which uses a python 3 environment for a segment of the app and thus the entirety of my repo’s environment is python 3.

When I run build -m --x64 to build for Mac (or the equivalent for windows) I get an error that node-gyp can’t find python2. I know that node-gyp is not compatible with python3… I normally have npm set to use python 2 for node-gyp with:npm config set python /usr/bin/python2.7

And anytime I use npm within a python 3 environment I don’t get an error about node-gpy not finding python2.

Also, within my project which has python 3.4.3 I can run electron-packager and create windows/mac builds without any errors from node-gyp being unable to find python 2.

But when I run electron-builder it seems that my environment has to be set to python 2. Two question I have are,

  1. How can I tell electron-builder the path to python 2 when it invokes node-gyp/electron-packager (if I understand how things work internally and I may not)…
  2. How is that electron-packager can package the same app in a python 3 environment but electron-builder needs the environments python to be strictly python 2 to work…

Right now I build a segment of my application using python 3 then switch to python 2 to build the rest since I’ve switched from electron-packager to electron-builder…

I can write scripts locally and on our CI (travis, appveyor) that do this python version switching but I’m hoping that won’t be unnecessary. For now I’ll have to do that to finish my work…

Below is the node-gyp error I get because my environment is in python 3,

$ build -m --x64                            
Rebuilding app dependencies for arch x64 to /Users/moi/Code/foo/otone_frontend/app

gyp ERR! configure error
gyp ERR! stack Error: Command failed: /opt/boxen/pyenv/shims/python2 -c import platform; print(platform.python_version());
gyp ERR! stack pyenv: python2: command not found
gyp ERR! stack
gyp ERR! stack The `python2' command exists in these Python versions:
gyp ERR! stack   2.7.5
gyp ERR! stack   2.7.7
gyp ERR! stack   2.7.9
gyp ERR! stack
gyp ERR! stack
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:202:12)
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:850:16)
gyp ERR! stack     at Socket.<anonymous> (internal/child_process.js:323: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:485:12)
gyp ERR! System Darwin 13.4.0
gyp ERR! command "/opt/boxen/nodenv/versions/v6.0.0/bin/node" "/opt/boxen/nodenv/versions/v6.0.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/moi/Code/foo/otone_frontend/app/node_modules/bufferutil
gyp ERR! node -v v6.0.0
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok

npm ERR! Darwin 13.4.0
npm ERR! argv "/opt/boxen/nodenv/versions/v6.0.0/bin/node" "/opt/boxen/nodenv/versions/v6.0.0/bin/npm" "rebuild" "--production"
npm ERR! node v6.0.0
npm ERR! npm  v3.8.6
npm ERR! code ELIFECYCLE
npm ERR! bufferutil@1.2.1 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bufferutil@1.2.1 install script 'node-gyp rebuild'.
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 bufferutil package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs bufferutil
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls bufferutil
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/moi/Code/foo/otone_frontend/app/npm-debug.log
Error: npm exited with code 1
    at ChildProcess.childProcess.on.code (/Users/moi/Code/foo/otone_frontend/node_modules/electron-builder/src/util/util.ts:132:14)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:850:16)
    at Socket.<anonymous> (internal/child_process.js:323:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:485:12)
From previous event:
    at spawn (/Users/moi/Code/foo/otone_frontend/node_modules/electron-builder/src/util/util.ts:109:9)
    at spawnNpmProduction (/Users/moi/Code/foo/otone_frontend/node_modules/electron-builder/src/util/util.ts:43:9)
    at Object.installDependencies (/Users/moi/Code/foo/otone_frontend/node_modules/electron-builder/src/util/util.ts:21:120)
    at Packager.<anonymous> (/Users/moi/Code/foo/otone_frontend/node_modules/electron-builder/src/packager.ts:214:34)
    at next (native)
    at tryOnImmediate (timers.js:543:15)
    at processImmediate [as _immediateCallback] (timers.js:523:5)
From previous event:
    at tsAwaiter (/Users/moi/Code/foo/otone_frontend/node_modules/electron-builder/src/util/awaiter.ts:10:47)
    at Object.build (/Users/moi/Code/foo/otone_frontend/node_modules/electron-builder/src/builder.ts:195:52)
    at Object.<anonymous> (/Users/moi/Code/foo/otone_frontend/node_modules/electron-builder/src/build-cli.ts:27:28)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Function.Module.runMain (module.js:575:10)
    at startup (node.js:159:18)
    at node.js:444:3

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

36reactions
Mazyodcommented, Oct 9, 2017

I could’ve sworn this didn’t work for me the first time, but running this solved the issue:

pyenv shell "2.7.10"

error I was getting:

gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /Users/.../.pyenv/shims/python2 -c import platform; print(platform.python_version());
gyp ERR! stack pyenv: python2: command not found
gyp ERR! stack 
gyp ERR! stack The `python2' command exists in these Python versions:
gyp ERR! stack   2.7.10
14reactions
develarcommented, Aug 4, 2016

I can run electron-packager and create windows/mac builds without any errors from node-gyp being unable to find python 2.

Because electron-package doesn’t rebuild native deps, but electron-builder does it for you.

npm config set python /usr/bin/python2.7

Very strange. Because we do call npm as cli, so, config must be respected. To investigate.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Still need Python2 · Issue #1977 · nodejs/node-gyp - GitHub
The Node v13 installer tried to install some node-gyp dependencies + Chocolatey, opened a command prompt which flashed an error message, then ...
Read more >
Python not found exception due to node-sass and node-gyp
The error message means that it cannot locate your python executable or binary. In many cases, it's installed at ...
Read more >
gyp err! stack error: can't find python executable - You.com
Solution 1 ⭐ The node-gyp installation instructions provide two options to get all of their necessary dependencies, including Python 2. Option 1 Install...
Read more >
Quickfix: NPM err: gyp verb check python checking for Python ...
Something was wrong while trying to execute the Python script when building. The error didn't make sense to me because the Pyton executable...
Read more >
Nodejs deployments failing with "gyp ERR! find Python" - Fly.io
Hello - My deployments are failing with an error message that node-gyp can't find python. My fly.toml [build] is configured as follows:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found