npm install 一时爽,gyp 来劝退

搬运自旧博客,不保证其时效性与可靠性

大部分时间是因为没有看官方文档……要用python27啊!!!

1
$ npm install -g node-gyp

You will also need to install:

  • On Unix:
    • python (v2.7 recommended, v3.x.x is not supported)
    • make
    • A proper C/C++ compiler toolchain, like GCC
  • On Mac OS X:
    • You also need to install the Command Line Tools via Xcode. You can find this under the menu Xcode-> Preferences -> Downloads
    • This step will install gcc and the related toolchain containing make
    • python (v2.7 recommended, v3.x.x is not supported) (already installed on Mac OS X)
    • Xcode
  • On Windows:
    • For 64-bit builds of node and native modules you will also need the Windows 7 64-bit SDK
    • You may need to run one of the following commands if your build complains about WindowsSDKDir not being set, and you are sure you have already installed the SDK:
    • Microsoft Visual Studio C++ 2013 for Windows Desktop (Express version works well)
    • Microsoft Visual Studio C++ 2013 (Express version works well)
    • If the install fails, try uninstalling any C++ 2010 x64&x86 Redistributable that you have installed first
    • If you get errors that the 64-bit compilers are not installed you may also need thecompiler update for the Windows SDK 7.1
    • Make sure that you have a PYTHON environment variable, and it is set to drive:\path\to\python.exe not to a folder
    • Python (v2.7.3 recommended, v3.x.x is not supported) 注意这里
    • Windows XP/Vista/7:
    • Windows 7/8:
    • All Windows Versions
1
2
call "C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\Setenv.cmd" /Release /x86
call "C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\Setenv.cmd" /Release /x64

If you have multiple Python versions installed, you can identify which Python version node-gyp uses by setting the ‘–python’ variable:

1
$ node-gyp --python /path/to/python2.7

If node-gyp is called by way of npm and you have multiple versions of Python installed, then you can set npm‘s ‘python’ config key to the appropriate value:

1
$ npm config set python /path/to/executable/python2.7

Note that OS X is just a flavour of Unix and so needs python, make, and C/C++. An easy way to obtain these is to install XCode from Apple, and then use it to install the command line tools (under Preferences -> Downloads).

Share