Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

Running Python on Windows for Node.js dependencies

I am getting into a Node.js codebase which requires that I download a few dependencies via NPM, namely jQuery.

In attempting to run npm install jquery, I keep getting this error:

Your environment has been set up for using Node.js 0.8.21 (x64) and NPM

C:UsersMatt Cashatt>npm install jquery
npm http GET https://registry.npmjs.org/jquery
npm http 304 https://registry.npmjs.org/jquery
npm http GET https://registry.npmjs.org/jsdom
npm http GET https://registry.npmjs.org/xmlhttprequest
npm http GET https://registry.npmjs.org/htmlparser/1.7.6
npm http GET https://registry.npmjs.org/location/0.0.1
npm http GET https://registry.npmjs.org/navigator
npm http GET https://registry.npmjs.org/contextify
npm http 304 https://registry.npmjs.org/htmlparser/1.7.6
npm http 304 https://registry.npmjs.org/xmlhttprequest
npm http 304 https://registry.npmjs.org/location/0.0.1
npm http 304 https://registry.npmjs.org/navigator
npm http 304 https://registry.npmjs.org/jsdom
npm http 304 https://registry.npmjs.org/contextify
npm http GET https://registry.npmjs.org/bindings
npm http GET https://registry.npmjs.org/cssom
npm http GET https://registry.npmjs.org/cssstyle
npm http GET https://registry.npmjs.org/request
npm http 304 https://registry.npmjs.org/bindings

> [email protected] install C:UsersMatt Cashatt
ode_modulesjquery
ode_module
scontextify
> node-gyp rebuild


C:UsersMatt Cashatt
ode_modulesjquery
ode_modulescontextify>node "C:Progr
am Files
odejs
ode_modules
pmin
ode-gyp-bin\....
ode_modules
ode-gyp
in
ode-gyp.js" rebuild
npm http 304 https://registry.npmjs.org/cssstyle
npm http 304 https://registry.npmjs.org/cssom
npm http 304 https://registry.npmjs.org/request
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYT
HON env variable.
gyp ERR! stack     at failNoPython (C:Program Files
odejs
ode_modules
pm
od
e_modules
ode-gyplibconfigure.js:113:14)
gyp ERR! stack     at C:Program Files
odejs
ode_modules
pm
ode_modules
ode
-gyplibconfigure.js:82:11
gyp ERR! stack     at Object.oncomplete (fs.js:297:15)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\Program Files\nodejs\node_modules\npm\node_modu
les\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:UsersMatt Cashatt
ode_modulesjquery
ode_modulescontextify
gyp ERR! node -v v0.8.21
gyp ERR! node-gyp -v v0.8.4
gyp ERR! not ok
npm ERR! error rolling back Error: ENOTEMPTY, rmdir 'C:UsersMatt Cashatt
ode_
modulesjquery
ode_modulesjsdom
ode_modules
equestests'
npm ERR! error rolling back  [email protected] { [Error: ENOTEMPTY, rmdir 'C:UsersM
att Cashatt
ode_modulesjquery
ode_modulesjsdom
ode_modules
equestests']
npm ERR! error rolling back   errno: 53,
npm ERR! error rolling back   code: 'ENOTEMPTY',
npm ERR! error rolling back   path: 'C:\Users\Matt Cashatt\node_modules\jque
ry\node_modules\jsdom\node_modules\request\tests' }
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! `cmd "/c" "node-gyp rebuild"` failed with 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the contextify 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 their info via:
npm ERR!     npm owner ls contextify
npm ERR! There is likely additional logging output above.

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nod
ejs\node_modules\npm\bin\npm-cli.js" "install" "jquery"
npm ERR! cwd C:UsersMatt Cashatt
npm ERR! node -v v0.8.21
npm ERR! npm -v 1.2.11
npm ERR! code ELIFECYCLE
npm ERR! Error: ENOENT, lstat 'C:UsersMatt Cashatt
ode_modulesjquery
ode_mo
dulesjsdom
ode_modules
equestestsest-pipes.js'
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nod
ejs\node_modules\npm\bin\npm-cli.js" "install" "jquery"
npm ERR! cwd C:UsersMatt Cashatt
npm ERR! node -v v0.8.21
npm ERR! npm -v 1.2.11
npm ERR! path C:UsersMatt Cashatt
ode_modulesjquery
ode_modulesjsdom
ode_
modules
equestestsest-pipes.js
npm ERR! fstream_path C:UsersMatt Cashatt
ode_modulesjquery
ode_modulesjsd
om
ode_modules
equestestsest-pipes.js
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! fstream_stack C:Program Files
odejs
ode_modules
pm
ode_modulesfst
reamlibwriter.js:284:26
npm ERR! fstream_stack Object.oncomplete (fs.js:297:15)
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:UsersMatt Cashatt
pm-debug.log
npm ERR! not ok code 0

C:UsersMatt Cashatt>

It looks like the failure is due to a missing Python installation. Well, I have installed Python, set the variable, and rebooted and still the error.

Any clue as to what I am missing?

Question&Answers:os

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

1 Reply

0 votes
by (71.8m points)

If you haven't got python installed along with all the node-gyp dependencies, simply open Powershell or Git Bash with administrator privileges and execute:

npm install --global --production windows-build-tools

and then to install the package:

npm install --global node-gyp

once installed, you will have all the node-gyp dependencies downloaded, but you still need the environment variable. Validate Python is indeed found in the correct folder:

C:Usersen.windows-build-toolspython27python.exe 

*Note - it uses python 2.7 not 3.x as it is not supported*

If it doesn't moan, go ahead and create your (user) environment variable:

setx PYTHON "%USERPROFILE%.windows-build-toolspython27python.exe"

restart cmd, and verify the variable exists via set PYTHON which should return the variable ($env:PYTHON if using Powershell)

Lastly re-apply npm install <module>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...