msgpack / msgpack-node

MessagePack implementation for Node.js
Other
311 stars 71 forks source link

Installation fails with Python 3 #46

Open zsmith3 opened 5 years ago

zsmith3 commented 5 years ago

I run the following: npm install msgpack

and get:

> msgpack@1.0.2 install {path}\node_modules\msgpack
> node-gyp rebuild

{path}\node_modules\msgpack>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Path\To\Python\Python36\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:276:12)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at maybeClose (internal/child_process.js:915:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd {path}\node_modules\msgpack
gyp ERR! node -v v8.12.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN photo-manager-fileserver No repository field.
npm WARN photo-manager-fileserver No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! msgpack@1.0.2 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the msgpack@1.0.2 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     {APPDATA}\npm-cache\_logs\2018-11-10T15_28_49_571Z-debug.log

Because I have Python 3.6 in my PATH, it attempts to use that to run a command which is designed for Python 2, so it fails to install.

I then ran the following:

set PATH=C:\Python27;C:\Program Files\nodejs
npm install --save msgpack

...and the installation worked fine. However, this step shouldn't be necessary, and I wouldn't have thought that having Python 3 in the PATH was such an unusual circumstance.

I don't know enough about NPM packaging to understand where the problem is (or how it might be fixed) but this seemed like the best place to post this issue.

aakropotkin commented 2 years ago

I'm bumping this because I this issue just consumed ~10 hours for me to debug.

This build operates under the assumption that the the shell command python ( whether by alias, symlink, or binary ) will invoke a Python 2.x interpreter.

There seems to be no attempt whatsoever by the build to "see if this system's python command is associated with v1, v2, or v3"; nor does it prompt the user in any sane manner when one could not be found - instead we get an incredibly unhelpful runtime crash from node-gyp indicating something to the effect of "file not found", or whatever Python v2/v3 syntax error happens to crop up first.

I am happy to make a PR to perform a rudimentary check for dependencies if someone would be kind enough to point me in the appropriate area of the code-base to dig into. I'm going to wager the node-gyp stuff might be the real culprit, but something like a "pre-build hook" would be an appropriate opportunity to run this type of audit.