nwjs / nw-gyp

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

Fails on python syntax even when setting options for python2 #156

Closed J7a4s0m5ine closed 1 year ago

J7a4s0m5ine commented 1 year ago

Running by specifying python version is failing nw-gyp --python="C:\Python27\python.exe" configure

Contextual information: Windows nw-gyp @ v3.6.6 node @ v18.13.0

I've tried numerous things including setting python in NPM config and system path to python2

PS C:\src\jsplayground\nw-tray-example-master\node_modules\robotjs> nw-gyp --python="C:\Python27\python.exe"  configure --target=0.72.0
gyp info it worked if it ends with ok
gyp info using nw-gyp@3.6.6
gyp info using node@18.13.0 | win32 | x64
gyp info find VS using VS2022 (17.0.31903.59) found at:
gyp info find VS "C:\Program Files\Microsoft Visual Studio\2022\Community"
gyp info find VS run with --verbose for detailed information
(node:12996) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
(Use `node --trace-deprecation ...` to show where the warning was created)
gyp info spawn C:\Python27\python.exe
gyp info spawn args [
gyp info spawn args   'C:\\Users\\username\\AppData\\Roaming\\npm\\node_modules\\nw-gyp\\gyp\\gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-G',
gyp info spawn args   'msvs_version=auto',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\src\\jsplayground\\nw-tray-example-master\\node_modules\\robotjs\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\username\\AppData\\Roaming\\npm\\node_modules\\nw-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\username\\.nw-gyp\\0.72.0\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\username\\.nw-gyp\\0.72.0',
gyp info spawn args   '-Dnode_gyp_dir=C:\\Users\\username\\AppData\\Roaming\\npm\\node_modules\\nw-gyp',
gyp info spawn args   '-Dnode_lib_file="C:\\Users\\username\\.nw-gyp\\0.72.0\\<(target_arch)\\node.lib"',
gyp info spawn args   '-Dnw_lib_file="C:\\Users\\username\\.nw-gyp\\0.72.0\\<(target_arch)\\nw.lib"',
gyp info spawn args   '-Dmodule_root_dir=C:\\src\\jsplayground\\nw-tray-example-master\\node_modules\\robotjs',
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   'C:\\src\\jsplayground\\nw-tray-example-master\\node_modules\\robotjs\\build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
  File "<string>", line 1
    import sys; print sys.byteorder
                ^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
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 (C:\Users\username\AppData\Roaming\npm\node_modules\nw-gyp\lib\configure.js:367:16)
gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:291:12)
gyp ERR! System Windows_NT 10.0.19045
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\username\\AppData\\Roaming\\npm\\node_modules\\nw-gyp\\bin\\nw-gyp.js" "--python=C:\\Python27\\python.exe" "configure" "--target=0.72.0"
gyp ERR! cwd C:\src\jsplayground\nw-tray-example-master\node_modules\robotjs
gyp ERR! node -v v18.13.0
gyp ERR! nw-gyp -v v3.6.6
gyp ERR! not ok
J7a4s0m5ine commented 1 year ago

Ah, I found a related issue

https://github.com/nwjs/nw-gyp/issues/122

J7a4s0m5ine commented 1 year ago

this problem was solved by using a few hints from this comment: https://github.com/nwjs/nw-gyp/issues/122#issuecomment-748871910

My solution slightly different. I opened files C:\Users\username\.nw-gyp\0.72.0\common.gypi and C:\Users\username\.nw-gyp\0.72.0\toolchain.gypi

Did a search and replace in both files for this

'v8_host_byteorder%': '<!(python -c "import sys; print sys.byteorder")'

and replaced with this:

 'v8_host_byteorder%': '<!(python -c "import sys; print(sys.byteorder)")',

Then used the following commands to configure and re-build

nw-gyp --python= C:\Python27\python.exe  configure --target=0.72.0 
nw-gyp rebuild --python="C:\Python27\python.exe" --target=0.72.0

You'll need to replace your paths and versions with the ones you're intending to use.

J7a4s0m5ine commented 1 year ago

Solved with work around