nwjs / nw-gyp

native addon build tool for node-webkit
MIT License
195 stars 50 forks source link

passing python2.7 path doesnot have effect #122

Open shalva97 opened 6 years ago

shalva97 commented 6 years ago

Hello, i have encountered a very annoying issue. The only workaround i have is to symlink python2.7 to python, which ofcourse breakes a lot of other programs on my system.

[shalva@archLinux loadCell2]$ cd node_modules/\@serialport/bindings/ [shalva@archLinux bindings]$ ls binding.gyp build CHANGELOG.md lib LICENSE package.json README.md src [shalva@archLinux bindings]$ nw-gyp configure --target=0.33.0 --python /usr/bin/python2.7 gyp info it worked if it ends with ok gyp info using nw-gyp@3.6.3 gyp info using node@10.10.0 | linux | x64 gyp info spawn /usr/bin/python2.7 gyp info spawn args [ '/usr/lib/node_modules/nw-gyp/gyp/gyp_main.py', gyp info spawn args 'binding.gyp', gyp info spawn args '-f', gyp info spawn args 'make', gyp info spawn args '-I', gyp info spawn args '/home/shalva/Projects/WebstormProjects/loadCell2/node_modules/@serialport/bindings/build/config.gypi', gyp info spawn args '-I', gyp info spawn args '/usr/lib/node_modules/nw-gyp/addon.gypi', gyp info spawn args '-I', gyp info spawn args '/home/shalva/.nw-gyp/0.33.0/common.gypi', gyp info spawn args '-Dlibrary=shared_library', gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=/home/shalva/.nw-gyp/0.33.0', gyp info spawn args '-Dnode_gyp_dir=/usr/lib/node_modules/nw-gyp', gyp info spawn args '-Dnode_lib_file="/home/shalva/.nw-gyp/0.33.0/<(target_arch)/node.lib"', gyp info spawn args '-Dnw_lib_file="/home/shalva/.nw-gyp/0.33.0/<(target_arch)/nw.lib"', gyp info spawn args '-Dmodule_root_dir=/home/shalva/Projects/WebstormProjects/loadCell2/node_modules/@serialport/bindings', gyp info spawn args '-Dnode_engine=v8', gyp info spawn args '--depth=.', gyp info spawn args '--no-parallel', gyp info spawn args '-Dv13=1', gyp info spawn args '--generator-output', gyp info spawn args 'build', gyp info spawn args '-Goutput_dir=.' ] File "", line 1 import sys; print sys.byteorder ^ SyntaxError: invalid syntax gyp: Call to 'python -c "import sys; print sys.byteorder"' returned exit status 1 while in binding.gyp. while trying to load binding.gyp gyp ERR! configure error gyp ERR! stack Error: gyp failed with exit code: 1 gyp ERR! stack at ChildProcess.onCpExit (/usr/lib/node_modules/nw-gyp/lib/configure.js:359:16) gyp ERR! stack at ChildProcess.emit (events.js:182:13) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12) gyp ERR! System Linux 4.18.6-arch1-1-ARCH gyp ERR! command "/usr/bin/node" "/usr/bin/nw-gyp" "configure" "--target=0.33.0" "--python" "/usr/bin/python2.7" gyp ERR! cwd /home/shalva/Projects/WebstormProjects/loadCell2/node_modules/@serialport/bindings gyp ERR! node -v v10.10.0 gyp ERR! nw-gyp -v v3.6.3 gyp ERR! not ok [shalva@archLinux bindings]$

it seems that there is hardcoded "python -c "import sys; print sys.byteorder" command....

P.S. this is my first issue on gihub so i wonder why code tag removes new lines? writing without it seems to be better....

corwin-of-amber commented 5 years ago

It took me a while but I managed to track down this command; it does not come from nw-gyp, but from an included file, deps/v8/gypfiles/toolchain.gypi that is part of the NW.js headers that nw-gyp downloads. (E.g., in my case it was downloaded from http://node-webkit.s3.amazonaws.com/v0.30.2/nw-headers-v0.30.2.tar.gz).

It seems like even Node.js devs were a bit perplexed about it (https://github.com/nodejs/node/issues/2735). There is a hack in Node.js that works around it by creating a symlink to python (https://github.com/nodejs/node/pull/16058), perhaps that can be ported back to nw-gyp.

trusktr commented 4 years ago

In case it helps anyone, I did something like this:

# switch to python2
sudo ln -sf python2 /usr/bin/python

# ... run nw-gyp commands ...

# restore `python` back to normal
sudo ln -sf python3 /usr/bin/python # on Arch/Manjaro Linux

More details at https://github.com/zeromq/zeromq.js/issues/405

corwin-of-amber commented 3 years ago

In Node, the issue has been patched two years ago by: https://github.com/nodejs/node/commit/3d8b844112bf6526ce126ecaec85f83b31a0a9aa

I could not quite find there the .gypi files are taken from to create the NWjs release files. Should maybe ask @TheJaredWilcurt.

FliiFe commented 3 years ago

Is there an actual fix (other than a hack that tampers with system files) ? Python2 has been discontinued for a year now, I reckon it would be about time to make the switch over to python3.

corwin-of-amber commented 3 years ago

I am using a different workaround until nwjs/node#46 is (hopefully) fixed: edit ~/.nw-gyp/0.49.2/config.gypi (replace 0.49.2 with your NWjs version) and change the offending print sys.byteorder to print(sys.byteorder).

Notice that this directory is only created after you have run nw-gyp for the first time with a given --target.