Please restart this script from an administrative PowerShell!

在这里插入图片描述
执行

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

报一下错误信息

Downloading python-2.7.15.amd64.msi
Downloading Python failed. Error: Error: getaddrinfo ENOTFOUND cdn.npmmirror.com
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26) {
errno: -3008,
code: ‘ENOTFOUND’,
syscall: ‘getaddrinfo’,
hostname: ‘cdn.npmmirror.com’
}
windows-build-tools will now exit.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! windows-build-tools@5.2.2 postinstall: node ./dist/index.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the windows-build-tools@5.2.2 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! D:\websoftware\nodeJS\nodejs\node_cache_logs\2023-01-06T09_07_41_306Z-debug.log

解决办法

cmd——右键——“管理员身份运行”

在这里插入图片描述
在这里插入图片描述

PS E:\tool\robot-project> node -v v16.20.2 PS E:\tool\robot-project> npm install --global windows-build-tools npm WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. npm WARN deprecated har-validator@5.1.5: this library is no longer supported npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 npm WARN deprecated windows-build-tools@5.2.2: Node.js now includes build tools for Windows. You probably no longer need this tool. See https://github.com/felixrieseberg/windows-build-tools for details. npm ERR! code 1 npm ERR! path D:\node_global\node_modules\windows-build-tools npm ERR! command failed npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node ./dist/index.js Downloading vs_BuildTools.exe npm ERR! [============================================>] 100.0% (0 B/s) npm ERR! Downloaded vs_BuildTools.exe. Saved to C:\Users\lijian\.windows-build-tools\vs_BuildTools.exe. npm ERR! npm ERR! Starting installation... npm ERR! Please restart this script from an administrative PowerShell! npm ERR! The build tools cannot be installed without administrative rights. npm ERR! To fix, right-click on PowerShell and run "as Administrator". npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\lijian\AppData\Local\npm-cache\_logs\2025-03-16T05_10_20_311Z-debug-0.log PS E:\tool\robot-project>
03-17
<think>嗯,用户遇到了安装windows-build-tools时出现错误的问题,特别是需要管理员权限的问题。首先,我得回忆一下相关的引用内容。根据引用[1],用户尝试过用管理员权限运行命令但没成功,而引用[5]提到可能需要手动安装Python和构建工具。另外,引用[3]提到可能是网络问题导致下载失败,或者头文件路径的问题。 我应该先建议用户以管理员身份运行命令提示符或PowerShell,这是基础步骤。然后检查系统环境,比如Python是否已经安装,或者是否有其他冲突的软件。如果直接安装失败,可能需要手动安装Visual Studio Build Tools和Python,这样能绕过npm安装的问题。 另外,用户可能遇到网络问题,比如下载依赖超时,这时候可以配置镜像源,比如使用淘宝的镜像,像引用[2]中提到的。还有,用户的环境变量可能有误,或者之前安装的残留导致冲突,引用[4]提到环境混乱可能引发问题,所以建议清理环境再尝试。 最后,如果所有方法都无效,可能需要使用替代方案,比如安装Visual Studio并选择C++桌面开发,或者使用其他构建工具。需要把这些步骤分点说明,确保用户能一步步排查问题。同时,生成相关问题时要覆盖常见的安装错误、手动安装步骤、网络配置和环境清理等,帮助用户全面了解可能的情况。</think>### 如何以管理员权限正确安装 windows-build-tools 解决 npm ERR! #### 1. 以管理员身份运行安装命令 - **步骤**:右键点击命令提示符(CMD)或 PowerShell,选择“以管理员身份运行”,然后执行命令: ```cmd npm install --global --production windows-build-tools ``` - 管理员权限可避免因权限不足导致的文件写入失败[^1][^4] - 若仍报错,尝试以下方法: #### 2. 检查系统环境配置 - **Python 版本要求**:确保系统已安装 Python 2.7 或 3.x,并配置环境变量 `PATH`(windows-build-tools 依赖 Python 编译原生模块)[^5] - **Visual Studio Build Tools**:手动安装 [Visual Studio Build Tools](https://visualstudio.microsoft.com/zh-hans/visual-cpp-build-tools/),勾选“C++ 桌面开发”组件[^5] #### 3. 使用镜像源加速安装 - **指定 Python 镜像源**(解决网络超时问题): ```cmd npm --python_mirror=https://registry.npmmirror.com/-/binary/python/ install --global windows-build-tools ``` 此命令通过国内镜像源加速 Python 下载[^2] #### 4. 清理冲突环境 - **卸载旧版本残留**:通过“控制面板”移除之前安装失败的 Python、Visual C++ 组件或 Node.js 原生模块 - **重置 npm 缓存**: ```cmd npm cache clean --force ``` #### 5. 替代方案(若仍失败) - **直接安装必要组件**: - 手动下载并安装 [Python](https://www.python.org/downloads/) 和 [Visual Studio Build Tools](https://aka.ms/vs/17/release/vs_BuildTools.exe) - 配置环境变量 `PYTHON` 指向 Python 安装路径[^3] - **使用 Chocolatey 包管理器**: ```cmd choco install python visualstudio2022buildtools -y ``` ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

曉儂

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值