npm install过程中python报错

更新于 阅读 23

最近将Mac系统升级到Ventura 13.4.1后发现python的默认版本为python3了,导致以前的旧项目在安装以来时报错,旧项目依赖的是python2。报错信息如下

gyp verb check python checking for Python executable "/usr/bin/python3" in the PATH gyp verb `which` succeeded /usr/bin/python3 /usr/bin/python3 gyp ERR! configure error gyp ERR! stack Error: Command failed: /usr/bin/python3 -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 Darwin 22.5.0 gyp ERR! command "/Users/tangzx/.nvm/versions/node/v14.18.3/bin/node" "/Users/tangzx/akulaku/ec-platform-console-goods/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" gyp ERR! cwd /Users/tangzx/akulaku/ec-platform-console-goods/node_modules/node-sass gyp ERR! node -v v14.18.3 gyp ERR! node-gyp -v v3.8.0 gyp ERR! not ok

安装依赖时直接执行:

npm install --python=python2

上面是指定python的版本为python2,就不需要改动系统默认的python版本了。