【用于解决 failed Error: not found: python2 node-sass】
报错信息如下:
```
npm WARN prefer global node-gyp@3.6.0 should be installed with -g
> node-sass@4.5.2 install E:\workspace_vscode\ww\node_modules\node-sass
> node scripts/install.js
Downloading binary from https://github.com/sass/node-sass/releases/download/v4.5 .2/win32-x64-48_binding.node
Cannot download "https://github.com/sass/node-sass/releases/download/v4.5.2/win3 2-x64-48_binding.node":
connect ETIMEDOUT 54.231.72.83:443
Timed out whilst downloading the prebuilt binary
Hint: If github.com is not accessible in your location
try setting a proxy via HTTP_PROXY, e.g.
export HTTP_PROXY=http://example.com:1234
or configure npm proxy via
npm config set proxy http://example.com:8080
> node-sass@4.5.2 postinstall E:\workspace_vscode\ww\node_modules\node-sass
> node scripts/build.js
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed at getNotFoundError
```
这个问题有两个解决方案
1. 按照提示需要 python2 环境,安装python2环境确实可以解决, 网上好多这种(管理员身份执行)。但是当你本来就有python环境时,环境变量不能自动替换,整起来就很麻烦。
```
npm install --global --production windows-build-tools
```
2. 第二种解决方案 ,看另一句报错,资源被墙。
```
Downloading binary from https://github.com/sass/node-sass/releases/download/v4.5.2/win32-x64-48_binding.node
Cannot download "https://github.com/sass/node-sass/releases/download/v4.5.2/win32-x64-48_binding.node":
```
下载此资源即可。下载后需要设置变量路径,防止它再次去下载。
可以设置环境变量 直接右键我的电脑--》属性--》高级系统设置--》环境变量--》添加
或者执行
```
set SASS_BINARY_PATH=D:\nodejs\tools\node-sass\win32-x64-46_binding.node
```
再次执行 npm install 成功
1