I get the following error when running npm install mongoose and any other package that depends on node-gyp:
if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node rebuild )
Traceback (most recent call last):
File "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp\gyp_main.py", line 15, in <module>
import gyp
ImportError: No module named gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:355:16)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Windows_NT 6.3.9600
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 C:\dev\Pluralsight\Web Development with ExpressJS\node_modules\kerberos
gyp ERR! node -v v4.2.2
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
Some details about my environment:
OS: Windows 8.1
node: v4.2.2
npm: v3.3.12
python: 2.7.9
What's causing this error and how can I fix it? Googling "no module named gyp" returns very little, and the solutions I've tried didn't work. I suspect the root issue is something other than what the error is hinting at.
What do C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp and its subdirectories contain?
Sorry for the late reply. The directory you mentioned contains the following:

None of the sub-directories are empty, do you need to see the contents inside of each one?
No, just pylib\gyp.
I apologize, I reset my computer to factory settings then followed these steps for making node-gyp work on windows and everything works fine now. Will re-open if I ever encounter this error again because I have no idea how to reproduce it from a fresh install of Windows.
I managed to reproduce the issue. Following the node-gyp Windows workaround here, the command
npm config set python python2.7
causes all npm installs relying on node-gyp to fail with the "no module named gyp" error. The fix was to just set python using the full path to the executable, as follows:
npm config set python C:\Python27\python.exe
This may cause a separate error, The imported project "C:\Microsoft.Cpp.Default.props" was not found. The fix for that is
set VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140
(See here)
@ericgrosse I keep getting no module named gyp and I tried npm config set python C:\Python27\python.exe but it has no effect.
Hi there!
anyone solved this issue ? Got the same thing.
Me too got the same issue.
@piccoloaiutante since you are the latest, could you provide the full output?
fwiw, even though I'm doing a different thing on a different operating system (trying to build this: https://github.com/awslabs/serverless-image-resizing), I'm getting the same error, so here's some output if it's of any use:
[......]
[email protected] install /home/ec2-user/serverless-resize/lambda/node_modules/sharp
node-gyp rebuild
Traceback (most recent call last):
File "/usr/bin/gyp", line 15, in
import gyp
ImportError: No module named 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/node-gyp/lib/configure.js:428:16)
gyp ERR! stack at ChildProcess.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:820:12)
gyp ERR! System Linux 3.4.37-40.44.amzn1.x86_64
gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/ec2-user/serverless-resize/lambda/node_modules/sharp
gyp ERR! node -v v0.10.48
gyp ERR! node-gyp -v v0.10.6
gyp ERR! not ok
npm ERR! weird error 1
npm ERR! not ok code 0
[ec2-user@domU-12-31-39-13-D1-5D lambda]$ which gyp
/usr/bin/gyp
[ec2-user@domU-12-31-39-13-D1-5D lambda]$ ll node_modules
total 8
drwxrwxr-x 10 ec2-user ec2-user 4096 May 2 15:12 aws-sdk
drwxrwxr-x 8 ec2-user ec2-user 4096 May 2 15:14 node-gyp
[ec2-user@domU-12-31-39-13-D1-5D lambda]$
@axlotl make sure you are using the latest npm version https://docs.npmjs.com/getting-started/installing-node (node-gyp is updated when npm is updated)
P.S. If you are using an EC2 machine, which template did you use (and which nodejs and npm do you have installed), I'll try to reproduce. To find installed versions run : npm version
P.P.S. I not a linux maven, but AFAIK node-gyp doesn't need GYP installed. It comes with it's own copy.
[ec2-user@domU-12-31-39-13-D1-5D lambda]$ which gyp
/usr/bin/gyp
@refack thank you, npm version was exactly the problem. It was freshly installed via yum but the ec2 instance was kind of old - I kind of figured yum would always give me the latest but I was wrong. Fixed by instantiating a new instance and installing on that.
In my case it was caused by the fact that I had python2.7 installed via cygwin and I needed to change the npm python variable npm config set python c:\Users\tomasfejfar\.windows-build-tools\python27\python.exe to location specified in https://github.com/nodejs/node-gyp#on-windows
Most helpful comment
I managed to reproduce the issue. Following the node-gyp Windows workaround here, the command
npm config set python python2.7causes all npm installs relying on node-gyp to fail with the "no module named gyp" error. The fix was to just set python using the full path to the executable, as follows:
npm config set python C:\Python27\python.exeThis may cause a separate error,
The imported project "C:\Microsoft.Cpp.Default.props" was not found. The fix for that isset VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140(See here)