最近在开发vue项目,执行npm install时,出现了关于python的相关错误,如下:

Binary found at D:\IdeaProjects\gykj-map-core\node_modules\node-sass\vendor\win32-x64-83\binding.node
Testing binary
Binary has a problem: Error: \\?\D:\IdeaProjects\gykj-map-core\node_modules\node-sass\vendor\win32-x64-83\binding.node is not a valid Win32 application.
\\?\D:\IdeaProjects\gykj-map-core\node_modules\node-sass\vendor\win32-x64-83\binding.node
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1144:18)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at module.exports (D:\IdeaProjects\gykj-map-core\node_modules\node-sass\lib\binding.js:19:10)
    at Object.<anonymous> (D:\IdeaProjects\gykj-map-core\node_modules\node-sass\lib\index.js:14:35)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32) {
  code: 'ERR_DLOPEN_FAILED'
}
Building the binary locally
Building: D:\Program Files\nodejs\node.exe D:\IdeaProjects\gykj-map-core\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cf
lags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   'D:\\Program Files\\nodejs\\node.exe',
gyp verb cli   'D:\\IdeaProjects\\gykj-map-core\\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@14.18.2 | 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 (D:\IdeaProjects\gykj-map-core\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (D:\IdeaProjects\gykj-map-core\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (D:\IdeaProjects\gykj-map-core\node_modules\which\which.js:80:29)
gyp verb `which` failed     at D:\IdeaProjects\gykj-map-core\node_modules\which\which.js:89:16
gyp verb `which` failed     at D:\IdeaProjects\gykj-map-core\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at D:\IdeaProjects\gykj-map-core\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:191:21)
gyp verb `which` failed  python2 Error: not found: python2
gyp verb `which` failed     at getNotFoundError (D:\IdeaProjects\gykj-map-core\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (D:\IdeaProjects\gykj-map-core\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (D:\IdeaProjects\gykj-map-core\node_modules\which\which.js:80:29)
gyp verb `which` failed     at D:\IdeaProjects\gykj-map-core\node_modules\which\which.js:89:16
gyp verb `which` failed     at D:\IdeaProjects\gykj-map-core\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at D:\IdeaProjects\gykj-map-core\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:191: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 C:\Users\hanbo\AppData\Local\Programs\Python\Python39\python.EXE
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Users\hanbo\AppData\Local\Programs\Python\Python39\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:383:12)
gyp ERR! stack     at ChildProcess.emit (events.js:400:28)
gyp ERR! stack     at maybeClose (internal/child_process.js:1058:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:293:5)
gyp ERR! System Windows_NT 10.0.19044
gyp ERR! command "D:\\Program Files\\nodejs\\node.exe" "D:\\IdeaProjects\\gykj-map-core\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--
libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd D:\IdeaProjects\gykj-map-core\node_modules\node-sass
gyp ERR! node -v v14.18.2
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

原因

这个是因为node-sass模型需要在本机进行编译,编译的时候,需要python2的环境,如果它无法获取到Python的路径的话,就会报这个错误。以本人电脑为例,我电脑上同时存在python2python3的环境,导致无法识别了。

解决办法

如果你电脑上已经安装过python2的环境,可以执行下面的代码,配置python路径,注意这个路径一定要是python.exe文件,所在的目录。

npm config set python C:\Python27

我的电脑上安装了ArcGIS,使用的是它自带的python环境,我电脑上的路径是C:\Python27\ArcGIS10.8
然后删除依赖,重新安装依赖,上面的问题就消失了。

rimraf node_modules
npm install
Logo

前往低代码交流专区

更多推荐