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 under MSYS2 #740

Closed
edmorley opened this issue Sep 23, 2015 · 11 comments
Closed

ImportError: No module named gyp under MSYS2 #740

edmorley opened this issue Sep 23, 2015 · 11 comments
Labels

Comments

@edmorley
Copy link

When trying to install karma on Windows 8.1 x64 on MSYS2, using node x64 v4.1.0, npm v2.14.3, MSYS2's python v2.7.10, GNU Make v4.1 (x86_64-pc-msys), gcc 4.9.2, Visual Studio express 2013, I get:

[~/src/gyp-tmp]$ npm install karma
npm WARN optional dep failed, continuing fsevents@0.3.8

> bufferutil@1.2.1 install C:\Users\Ed\src\gyp-tmp\node_modules\karma\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\bufferutil
> node-gyp rebuild


C:\Users\Ed\src\gyp-tmp\node_modules\karma\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\bufferutil>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:\Users\Ed\src\gyp-tmp\node_modules\karma\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\bufferutil
gyp ERR! node -v v4.1.0
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok

The verbose output contains:

> utf-8-validate@1.2.1 install C:\Users\Ed\src\gyp-tmp\node_modules\karma\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate
> node-gyp rebuild

C:\Users\Ed\src\gyp-tmp\node_modules\karma\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate>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 )
gyp info it worked if it ends with ok
gyp verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
gyp verb cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli   'rebuild' ]
gyp info using node-gyp@3.0.3
gyp info using node@4.1.0 | win32 | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` succeeded python2 C:\msys64\usr\bin\python2.EXE
gyp verb check python version `python2 -c "import platform; print(platform.python_version());"` returned: "2.7.10\n"
gyp verb get node dir no --target version specified, falling back to host node version: 4.1.0
gyp verb command install [ '4.1.0' ]
gyp verb install input version string "4.1.0"
gyp verb install installing version: 4.1.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 4.1.0
gyp verb build dir attempting to create "build" dir: C:\Users\Ed\src\gyp-tmp\node_modules\karma\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate\build
gyp verb build dir "build" dir needed to be created? C:\Users\Ed\src\gyp-tmp\node_modules\karma\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate\build
gyp verb build/config.gypi creating config file
gyp verb build/config.gypi writing out config file: C:\Users\Ed\src\gyp-tmp\node_modules\karma\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate\build\config.gypi
gyp verb config.gypi checking for gypi file: C:\Users\Ed\src\gyp-tmp\node_modules\karma\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate\config.gypi
gyp verb common.gypi checking for gypi file: C:\Users\Ed\src\gyp-tmp\node_modules\karma\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate\common.gypi
gyp verb gyp gyp format was not specified; forcing "msvs"
gyp info spawn python2
gyp info spawn args [ 'C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-G',
gyp info spawn args   'msvs_version=auto',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\Ed\\src\\gyp-tmp\\node_modules\\karma\\node_modules\\socket.io\\node_modules\\engine.io\\node_modules\\ws\\node_modules\\utf-8-validate\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\Ed\\.node-gyp\\4.1.0\\include\\node\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\Ed\\.node-gyp\\4.1.0',
gyp info spawn args   '-Dnode_gyp_dir=C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp',
gyp info spawn args   '-Dnode_lib_file=node.lib',
gyp info spawn args   '-Dmodule_root_dir=C:\\Users\\Ed\\src\\gyp-tmp\\node_modules\\karma\\node_modules\\socket.io\\node_modules\\engine.io\\node_modules\\ws\\node_modules\\utf-8-validate',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'C:\\Users\\Ed\\src\\gyp-tmp\\node_modules\\karma\\node_modules\\socket.io\\node_modules\\engine.io\\node_modules\\ws\\node_modules\\utf-8-validate\\build',
gyp info spawn args   '-Goutput_dir=.' ]
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:\Users\Ed\src\gyp-tmp\node_modules\karma\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate
gyp ERR! node -v v4.1.0
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok

I have visual studio express 2013 installed - though since I'm using MSYS2's python package (installed via pacman) some things try and use MSYS2's gcc instead - not sure which node-gyp should be using, or at least is trying to use.

If I'm missing a dependency or something isn't set, it would be really helpful if node-gyp failed early with an informative error message, rather than the above.

Also, after the errors are shown, karma still ends up installed (though presumably in a broken state) - npm/karma/... bug?

@edmorley
Copy link
Author

Annotating gyp_main.py shows that for some reason os.path.dirname(sys.argv[0]) was equal to the empty string, such that it was then only appending the string pylib (and not the absolute path to the directory) to sys.path.

If I change:
sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), 'pylib'))
to:
sys.path.append(os.path.join(sys.path[0], 'pylib'))
...the import works fine.

(I then hit a later issue, but that looks unrelated and hopefully easy to solve: MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe".).

@mkscrg
Copy link

mkscrg commented Mar 8, 2016

Any MSYS users find a way around this? cc @edmorley

@ghost
Copy link

ghost commented Aug 3, 2016

Issue still exists for me. The workaround didn't work either.

D:\Entwicklung\Electron\muhbot\node_modules\ref>if not defined npm_config_node_g
yp (node "D:\Programme\Node\node_modules\npm\bin\node-gyp-bin\\..\..\node_module
s\node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebuild )
Traceback (most recent call last):
  File "D:\Programme\Node\node_modules\npm\node_modules\node-gyp\gyp\gyp_main.py
", line 13, 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 (D:\Programme\Node\node_modules\npm\
node_modules\node-gyp\lib\configure.js:305:16)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_proces
s.js:204:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "D:\\Programme\\Node\\node.exe" "D:\\Programme\\Node\\node_modu
les\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\Entwicklung\Electron\muhbot\node_modules\ref
gyp ERR! node -v v6.2.0
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok
npm WARN install:ref@1.3.2 ref@1.3.2 install: `node-gyp rebuild`
npm WARN install:ref@1.3.2 Exit status 1

Tried to install "discord.js".

@strawhatguy
Copy link

@mkscrg @Sogomn I know this is a year old but for what it's worth, I ran into this problem at work just today.

Basically, if you've put the MSYS2 bin directories in your PATH (I had C:\msys64\usr\bin;C:\msys64\mingw64\bin for instance) the python os.path.dirname(sys.argv[0]) mentioned earlier in this thread returns a blank string.

I believe it is because with the bin dirs of MSYS2 visible, the os.path module of python seems to think it's on a unix box, with / path separators, rather than on a windows box, which has \ separators. I haven't dug into the python codebase to confirm that yet.

@ghost
Copy link

ghost commented Sep 17, 2016

@strawhatguy My solution was to use the Python executable from the "Windows build tools". I previously used the one I downloaded with MSYS which seemed to cause the error.

@jeromewu
Copy link

jeromewu commented Oct 4, 2016

I solve the issue by using the command in msys2

npm config set python /c/Python27/python

And I also have some issues in the build phase and solved by installing the latest npm

npm install -g npm@next

Hope this will help :)

@Darker
Copy link

Darker commented Jan 26, 2017

I have this exact problem too. I fixed it by installing windows build tools like this:

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

Then adding the correct python path:

npm config set python "C:\Users\USERNAME\.windows-build-tools\python27\python.exe"

@strawhatguy
Copy link

@Sogomn @Darker I think I actually tried the windows build tools at one point, and couldn't get it to work, but this was a while ago now.
Glad you got yours working!

@ghost
Copy link

ghost commented Jan 26, 2017

@strawhatguy I simply switched to Linux which makes things magically work.

@strawhatguy
Copy link

Yeah I'm missing Linux in my current job

@maclover7
Copy link
Contributor

Going to give this a close since it seems like the issue was an incorrectly configured Python installation

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

No branches or pull requests

7 participants