简体   繁体   English

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

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

I edit my PATH of node-gyp and cannot return it back to normal.我编辑了 node-gyp 的 PATH 并且无法将其恢复正常。 So if I type所以如果我输入

 node-gyp -v 

it opens a node-gyp.js file itself.它会打开一个node-gyp.js文件本身。

How should I change my PATH of node-gyp to return it back to normal?我应该如何更改 node-gyp 的PATH以使其恢复正常?

You can install with npm read me :您可以使用 npm 安装阅读我

$ npm install -g node-gyp

You will also need to install:您还需要安装:

On Windows:在 Windows 上:

Python (v2.7.10 recommended, v3.xx is not supported) Python(推荐v2.7.10,不支持v3.xx)

Make sure that you have a PYTHON environment variable, and it is set to drive:\path\to\python.exe not to a folder确保您有一个 PYTHON 环境变量,并将其设置为 drive:\path\to\python.exe 而不是文件夹

Windows XP/Vista/7: Windows XP/Vista/7:

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

  • If the install fails, try uninstalling any C++ 2010 x64&x86 Redistributable that you have installed first如果安装失败,请尝试卸载您首先安装的任何 C++ 2010 x64&x86 Redistributable
  • If you get errors that the 64-bit compilers are not installed you may also need the compiler update for the Windows SDK 7.1如果您收到未安装 64 位编译器的错误,您可能还需要 Windows SDK 7.1 的编译器更新

Windows 7/8: Windows 7/8:

Microsoft Visual Studio C++ 2013 for Windows Desktop (Express version works well) Microsoft Visual Studio C++ 2013 用于 Windows 桌面(快捷版运行良好)

Windows 10: Windows 10:

All Windows Versions所有 Windows 版本

For 64-bit builds of node and native modules you will also need the Windows 7 64-bit SDK对于节点和本机模块的 64 位构建,您还需要Windows 7 64 位 SDK

You may need to run one of the following commands if your build complains about WindowsSDKDir not being set, and you are sure you have already installed the 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

If you have multiple Python versions installed, you can identify which Python version node-gyp uses by setting the '--python' variable:如果您安装了多个 Python 版本,您可以通过设置“--python”变量来识别 node-gyp 使用的 Python 版本:

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

If node-gyp is called by way of npm and you have multiple versions of Python installed, then you can set npm's 'python' config key to the appropriate value:如果通过 npm 调用 node-gyp 并且您安装了多个版本的 Python,那么您可以将 npm 的“python”配置键设置为适当的值:

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

As a reminder, you should include the entire folder that contains the module as a path to Windows.提醒一下,您应该包含包含模块的整个文件夹作为 Windows 的路径。 Add an environment variable called NODE_PATH and set it to %USERPROFILE%\Application Data\npm\node_modules (Windows XP), %AppData%\npm\node_modules (Windows 7/8/10), or wherever npm ends up installing the modules on your Windows flavor.添加一个名为 NODE_PATH 的环境变量并将其设置为 %USERPROFILE%\Application Data\npm\node_modules (Windows XP)、%AppData%\npm\node_modules (Windows 7/8/10) 或 npm 最终安装模块的位置你的 Windows 味道。 To be done with it once and for all, add this as a System variable in the Advanced tab of the System Properties dialog (run control.exe sysdm.cpl,System,3).要一劳永逸地完成它,请将其添加为“系统属性”对话框的“高级”选项卡中的系统变量(运行 control.exe sysdm.cpl,System,3)。

Quick solution in Windows 7+ is to just run: Windows 7+ 中的快速解决方案是运行:

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

It's worth to mention that NODE_PATH is only used when importing modules in Node apps.值得一提的是,NODE_PATH 仅在 Node 应用程序中导入模块时使用。 When you want to use globally installed modules' binaries in your CLI you need to add it also to your PATH, but without node_modules part (for example %AppData%\npm in Windows 7/8/10).当您想在 CLI 中使用全局安装的模块的二进制文件时,您还需要将其添加到 PATH,但没有 node_modules 部分(例如 Windows 7/8/10 中的 %AppData%\npm)。

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

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