Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: No module named gyp #807

Closed
ericgrosse opened this issue Nov 8, 2015 · 13 comments
Closed

ImportError: No module named gyp #807

ericgrosse opened this issue Nov 8, 2015 · 13 comments

Comments

@ericgrosse
Copy link

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.

@bnoordhuis
Copy link
Member

What do C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\gyp and its subdirectories contain?

@ericgrosse
Copy link
Author

Sorry for the late reply. The directory you mentioned contains the following:

node-gyp-1

None of the sub-directories are empty, do you need to see the contents inside of each one?

@bnoordhuis
Copy link
Member

No, just pylib\gyp.

@ericgrosse
Copy link
Author

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.

@ericgrosse
Copy link
Author

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)

@manvir-singh
Copy link

@ericgrosse I keep getting no module named gyp and I tried npm config set python C:\Python27\python.exe but it has no effect.

@kounkou
Copy link

kounkou commented Jan 26, 2017

Hi there!
anyone solved this issue ? Got the same thing.

@piccoloaiutante
Copy link
Member

Me too got the same issue.

@refack
Copy link
Contributor

refack commented Apr 29, 2017

@piccoloaiutante since you are the latest, could you provide the full output?

@axlotl
Copy link

axlotl commented May 3, 2017

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]$

@refack
Copy link
Contributor

refack commented May 3, 2017

@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

@axlotl
Copy link

axlotl commented May 3, 2017

@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.

@tomasfejfar
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants