报错:Can‘t find Python executable “python“, you can set the PYTHON env variable
人民网>>社会·法治

报错:Can‘t find Python executable “python“, you can set the PYTHON env variable

2025-06-24 12:20:54 | 来源:人民网
小字号

导入项目。vscode。,执行。npm install命。命令后,报错了,报错信息是node-sass安装失败,提示python环境中的错误信息,这是因为安装node-sass失败了,而node-sass依赖于Python环境。


1.报错:Can't find Python executable "python", you can set the PYTHON env variable 。

解决方案:安装windows-build-tools。

npm install --global --production windows-build-tools。

如果您输入上述代码,请输入Pleaseee restart this script from an administrative PowerShell!错误,需要在管理员的权限下运行 。

搜索cmd󿀌然后右键“作为管理员运行”再次运行。

npm install --global --production windows-build-tools。

然后,如果python2.7出现,说明电脑上没有python环境󿀌下载以下管网。

Python Release Python 2.7.12 | Python.org。

直接下载安装即可,将安装的Python添加到环境变量中。

配置环境变量:

  • 右键是“我的电脑”--->属性---->高级系统设置--->弹出“系统属性”界面---->选择先进的环境变量。

  • 在以下“系统变量”中找到“Path",然后点击“编辑",将Python的安装目录“C:填写Python27,#xff0c;注意,两条路径之间有“两条路径”;分号分开。
  • 输入后点击“确定”即可。
  • 然后验证,通过快捷键“通过快捷键”windows+R打开“运行”,然后输入“cmd打开命令行窗口,输入“python-V命令,回车后,将打印当前python版本信息,这说明我们的Python安装已经完成,并配置环境变量。

 安装node-gyp,以确保所有工具的正常运行。     重复上述步骤。

npm install --global node-gyp。

2. 。node升版后,node版本不适合node-sassc;解决办法。

node升级版本后,运行npm run serve命令时,会出现以下错误󿀌提示运行npmmm install命令导致环境变化,npm需要运行 rebuild node-sass重新配置环境。

node。 版本、。node-sass。 版本及 。sass-loader。 查看版本:

 。node。 查看版本:
输入命令行查询命令󿄚node -v。

node。 版本与 。node-sass。 版本的对应关系:

3.CERT_HAS_EXPIRED 。

遇到。CERT_HAS_EXPIRED。错误通常意味着尝试连接服务器的SSL证书已经过期。这个问题可能出现在你使用的npm镜像中。

更换npm镜像源。
如果问题是由特定镜像源的证书问题引起的,尝试更换官方npm镜像源或其他镜像源:

切换到npm官方镜像源:

npm config set registry https://registry.npmjs.org/。

或者,使用其他可用的镜像源,例如,华为云镜像源:

npm config set registry https://mirrors.huaweicloud.com/repository/npm/。

(责编:人民网)

分享让更多人看到