繁体   English   中英

Windows 上的 node-gyp 标准路径是什么?

[英]What is the node-gyp standard PATH on Windows?

我编辑了 node-gyp 的 PATH 并且无法将其恢复正常。 所以如果我输入

 node-gyp -v 

它会打开一个node-gyp.js文件本身。

我应该如何更改 node-gyp 的PATH以使其恢复正常?

您可以使用 npm 安装阅读我

$ npm install -g node-gyp

您还需要安装:

在 Windows 上:

Python(推荐v2.7.10,不支持v3.xx)

确保您有一个 PYTHON 环境变量,并将其设置为 drive:\path\to\python.exe 而不是文件夹

Windows XP/Vista/7:

Microsoft Visual Studio C++ 2013(Express 版运行良好)

  • 如果安装失败,请尝试卸载您首先安装的任何 C++ 2010 x64&x86 Redistributable
  • 如果您收到未安装 64 位编译器的错误,您可能还需要 Windows SDK 7.1 的编译器更新

Windows 7/8:

Microsoft Visual Studio C++ 2013 用于 Windows 桌面(快捷版运行良好)

Windows 10:

所有 Windows 版本

对于节点和本机模块的 64 位构建,您还需要Windows 7 64 位 SDK

如果您的构建抱怨没有设置 WindowsSDKDir,您可能需要运行以下命令之一,并且您确定您已经安装了 SDK:

call "C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\Setenv.cmd" /Release /x86
call "C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\Setenv.cmd" /Release /x64

如果您安装了多个 Python 版本,您可以通过设置“--python”变量来识别 node-gyp 使用的 Python 版本:

$ node-gyp --python /path/to/python2.7

如果通过 npm 调用 node-gyp 并且您安装了多个版本的 Python,那么您可以将 npm 的“python”配置键设置为适当的值:

$ npm config set python /path/to/executable/python2.7

提醒一下,您应该包含包含模块的整个文件夹作为 Windows 的路径。 添加一个名为 NODE_PATH 的环境变量并将其设置为 %USERPROFILE%\Application Data\npm\node_modules (Windows XP)、%AppData%\npm\node_modules (Windows 7/8/10) 或 npm 最终安装模块的位置你的 Windows 味道。 要一劳永逸地完成它,请将其添加为“系统属性”对话框的“高级”选项卡中的系统变量(运行 control.exe sysdm.cpl,System,3)。

Windows 7+ 中的快速解决方案是运行:

rem for future
setx NODE_PATH %AppData%\npm\node_modules
rem for current session
set NODE_PATH=%AppData%\npm\node_modules

值得一提的是,NODE_PATH 仅在 Node 应用程序中导入模块时使用。 当您想在 CLI 中使用全局安装的模块的二进制文件时,您还需要将其添加到 PATH,但没有 node_modules 部分(例如 Windows 7/8/10 中的 %AppData%\npm)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM