Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

javascript - Node.js (npm) refuses to find python even after %PYTHON% has been set

So I am trying to get the Node.js to work. Of course, it's not as easy as advertised :)

I happen to have two python versions on my computer, but Node.js seems to only work with the older one, 2.7. Upon error, it also encourages me to set the path into PYTHON environment variable with this error:

Error: Can't find Python executable "python2.7", you can set the PYTHON env variable.

Ok then, I configured the variable as desired:

C:UsersJakub>set PYTHON=C:MYSELFProgramsPython2.7python.exe

C:UsersJakub>echo %PYTHON%
C:MYSELFProgramsPython2.7python.exe

You can see that I used echo to check whether the variable was really set. Unfortunatelly, that npm thing can't read it and the error appears again. Here's the full log right after I set the %PYTHON% variable:

C:UsersJakub>npm install minecraft-protocol



> [email protected] install C:UsersJakub
ode_modulesminecraft-protocol
ode_modulesursa
> node-gyp rebuild

|
C:UsersJakub
ode_modulesminecraft-protocol
ode_modulesursa>if not defined npm_config_node_gyp (node "C:Program Files (x86)
odejs
ode_modules
pmin
ode-gyp-bin\....
o
de_modules
ode-gypin
ode-gyp.js" rebuild )  else (rebuild)
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python2.7", you can set the PYTHON env variable.
gyp ERR! stack     at failNoPython (C:Program Files (x86)
odejs
ode_modules
pm
ode_modules
ode-gyplibconfigure.js:103:14)
gyp ERR! stack     at C:Program Files (x86)
odejs
ode_modules
pm
ode_modules
ode-gyplibconfigure.js:64:11
gyp ERR! stack     at FSReqWrap.oncomplete (evalmachine.<anonymous>:95:15)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I figured out the most stable solution is to set python npm internal value to actual path:

npm config set python C:ProgramsPython2.7python2.7.exe

This skips all environment variable and %PATH% crap and just starts the python wherever it's installed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...