创建Vue项目报错python.EXE -c import sys; print “%s.%s.%s“ % sys.version_info[:3];

1、错误情况

gyp verb `which` succeeded python C:\Users\Software\Python\Python310\python.EXE
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Users\Software\Python\Python310\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: Missing parentheses in call to 'print'. Did you mean print(...)?
gyp ERR! stack
gyp ERR! stack     at ChildProcess.exithandler (node:child_process:399:12)
gyp ERR! stack     at ChildProcess.emit (node:events:526:28)
gyp ERR! stack     at maybeClose (node:internal/child_process:1092:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
gyp ERR! System Windows_NT 10.0.22000
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\18084\\Desktop\\phase-3\\fresh-market-master\\fresh-market-master\\生鲜超市\\online-store\\node_modules\\[email protected]@node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd C:\Users\18084\Desktop\phase-3\fresh-market-master\fresh-market-master\生鲜超市\online-store\node_modules\_node-sass@4.14.1@node-sass
gyp ERR! node -v v16.14.2
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
[npminstall:runscript:error] node-sass@^4.5.2 scripts.postinstall run "node scripts/build.js" error: Error [RunScriptError]: Run "C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js" error, exit code 1
    at ChildProcess.<anonymous> (C:\Users\18084\AppData\Roaming\npm\node_modules\cnpm\node_modules\runscript\index.js:96:21)
    at ChildProcess.emit (node:events:526:28)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12) {
    
    
  stdio: [Object],
  exitcode: 1
}
× Install fail! RunScriptError: post install error, please remove node_modules before retry!
Run "C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js" error, exit code 1
RunScriptError: Run "C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js" error, exit code 1
    at ChildProcess.<anonymous> (C:\Users\18084\AppData\Roaming\npm\node_modules\cnpm\node_modules\runscript\index.js:96:21)
    at ChildProcess.emit (node:events:526:28)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
npminstall version: 5.8.0
npminstall args: C:\Program Files\nodejs\node.exe C:\Users\18084\AppData\Roaming\npm\node_modules\cnpm\node_modules\npminstall\bin\install.js --fix-bug-versions --china --userconfig=C:\Users\18084\.cnpmrc --disturl=https://npmmirror.com/mirrors/node --registry=https://registry.npmmirror.com

在这里插入图片描述
2、产生原因

创建vue2.x项目时选用手动配置项目依赖时如果CSS样式器选择的是(with node-sass)就会报出上面的错误:

编译失败的原因其大的方向就两点:
①程序本身存在语法错误或语义错误;
②编译环境存在问题导致无法编译(常见的就是缺少相关依赖和插件);
在这里插入图片描述
3、解决方案

①.下载安装node.js时最后一定要选择自动安装编译本地模块所需的工具(自己手动下载难度大,建议使用这个方法)
在这里插入图片描述
② 上面那个选项说的很明白了如果采用自动安装那么也必然会安装Chocolatey,(那么安装Chocolate是采用了远程脚本的一种方式且会在Windows PowerShell中进行,而使用PowerShell首先必须确保Get-ExecutionPolicy不受限制。(建议使用Bypass绕过该策略来安装或AllSigned安全性更高) 因为windows PowerShell的执行策略默认是禁止运行脚本的所以我们需要修改组策略。

<1>首先运行Get-ExecutionPolicy
<2>如果返回Restricted,则运行Set-ExecutionPolicy AllSigned或Set-ExecutionPolicy Bypass

PS C:\Users\18084> Set-ExecutionPolicy -ExecutionPolicy Bypass
PS C:\Users\18084>  Get-ExecutionPolicy
Bypass
PS C:\Users\18084> Set-ExecutionPolicy -ExecutionPolicy AllSigned
PS C:\Users\18084>  Get-ExecutionPolicy
AllSigned
PS C:\Users\18084>

在这里插入图片描述
③ PowerShell 脚本调整脚本的执行策略。比如设置成不会限制脚本执行的 Bypass命令:

Set-ExecutionPolicy -ExecutionPolicy Bypass

node:注意,设置脚本的执行策略需要管理员权限,因此你需要以管理员权限启动 PowerShell ,然后执行上面的命令。

必须执行策略允许运行脚本才可以执行node.js的自动安装不然会安装失败

4、成功之后,安装vue的脚手架,执行命令:

npm install

出现报错:

扫描二维码关注公众号,回复: 14224562 查看本文章
[email protected]: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.

在这里插入图片描述

方法:

npm install --save core-js@^3

猜你喜欢

转载自blog.csdn.net/qq_22938603/article/details/124307421
sys