node-sass下载失败 not found: python2

前端项目一般都需要一些依赖包:直接通过npm i或者yarn install直接安装依赖可能安装失败,这里就给大家分享一个案例:

        本人用得公司得镜像源,项目又是别得部门开发的,转到我这个部门过来。先给大家讲下快速接手已开发的项目步骤:查看项目主要技术和框架、询问nodejs版本,npm或者yarn也应该是对应的版本、查看package.json文件(可以看到项目启动方式、npm或者yarn)。安装依赖(npm i或者yarn install)、配置文件(一般是config命名的).....

直奔主题我这里是第一次用node-sass:在下载依赖包的时候下载失败了,提示如下:

Building: G:\nodejs\node.exe F:\test\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   'G:\\nodejs\\node.exe',
gyp verb cli   'F:\\test\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library='
gyp verb cli ]
gyp info using node-gyp@3.8.0
gyp info using node@12.13.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` failed Error: not found: python2
gyp verb `which` failed     at getNotFoundError (F:\test\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (F:\test\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (F:\test\node_modules\which\which.js:80:29)
gyp verb `which` failed     at F:\test\node_modules\which\which.js:89:16
gyp verb `which` failed     at F:\test\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at F:\test\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:158:21)
gyp verb `which` failed  python2 Error: not found: python2
gyp verb `which` failed     at getNotFoundError (F:\test\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (F:\test\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (F:\test\node_modules\which\which.js:80:29)
gyp verb `which` failed     at F:\test\node_modules\which\which.js:89:16
gyp verb `which` failed     at F:\test\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at F:\test\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:158:21) {
gyp verb `which` failed   stack: 'Error: not found: python2\n' +
gyp verb `which` failed     '    at getNotFoundError (F:\\test\\node_modules\\which\\which.js:13:12)\n' +
gyp verb `which` failed     '    at F (F:\\test\\node_modules\\which\\which.js:68:19)\n' +
gyp verb `which` failed     '    at E (F:\\test\\node_modules\\which\\which.js:80:29)\n' +
gyp verb `which` failed     '    at F:\\test\\node_modules\\which\\which.js:89:16\n' +
gyp verb `which` failed     '    at F:\\test\\node_modules\\isexe\\index.js:42:5\n' +
gyp verb `which` failed     '    at F:\\test\\node_modules\\isexe\\windows.js:36:5\n' +
gyp verb `which` failed     '    at FSReqCallback.oncomplete (fs.js:158:21)',
gyp verb `which` failed   code: 'ENOENT'
gyp verb `which` failed }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` succeeded python G:\Python\Python37-32\python.EXE
gyp ERR! configure error
gyp ERR! stack Error: Command failed: G:\Python\Python37-32\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                                ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:295:12)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "G:\\nodejs\\node.exe" "F:\\test\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsas
s_library="
gyp ERR! cwd F:\test\node_modules\node-sass
gyp ERR! node -v v12.13.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.11.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.11.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2019-11-18T07_33_10_767Z-debug.log

Process finished with exit code 1
 

这是因为node-sass需要依赖python和Visual Studio,而下载这两个失败了,导致node-sass下载失败了。

解决方式(以npm为例,yarn是同理的):

        1.先删除npm i下载的依赖node-modules文件

        2.以管理员身份打开命令提示行运行:

                npm install -g windows-build-tools

                如果这里运行失败了,是因为镜像源地址错了。需要修改地址

                        镜像改为淘宝镜像源:npm config set registry https://registry.npm.taobao.org

                        代理也不能错,要么用taobao,要么置空:npm config proxy null

​​​​​​​                         (对上面node 配置镜像源地址看不懂,可以看这篇文章npm config详解_小桥路上的博客-CSDN博客

                        再执行npm install -g windows-build-tools

        3.到这里表示安装好了,可以直接ctrl c关闭

         4.然后就可以直接再npm i下载了。

注释:遇到这个错误npm install error: tunneling socket could not be established可以直接将代理置空再看:npm config proxy null

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【用于解决 failed Error: not found: python2 node-sass】 报错信息如下: ``` npm WARN prefer global [email protected] 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 成功

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值