Mat*_*att 217 python windows node.js npm
我正在进入Node.js代码库,这需要我通过NPM下载一些依赖项,即jQuery.
在尝试运行时npm install jquery,我不断收到此错误:
Your environment has been set up for using Node.js 0.8.21 (x64) and NPM
C:\Users\Matt Cashatt>npm install jquery
npm http GET https://registry.npmjs.org/jquery
npm http 304 https://registry.npmjs.org/jquery
npm http GET https://registry.npmjs.org/jsdom
npm http GET https://registry.npmjs.org/xmlhttprequest
npm http GET https://registry.npmjs.org/htmlparser/1.7.6
npm http GET https://registry.npmjs.org/location/0.0.1
npm http GET https://registry.npmjs.org/navigator
npm http GET https://registry.npmjs.org/contextify
npm http 304 https://registry.npmjs.org/htmlparser/1.7.6
npm http 304 https://registry.npmjs.org/xmlhttprequest
npm http 304 https://registry.npmjs.org/location/0.0.1
npm http 304 https://registry.npmjs.org/navigator
npm http 304 https://registry.npmjs.org/jsdom
npm http 304 https://registry.npmjs.org/contextify
npm http GET https://registry.npmjs.org/bindings
npm http GET https://registry.npmjs.org/cssom
npm http GET https://registry.npmjs.org/cssstyle
npm http GET https://registry.npmjs.org/request
npm http 304 https://registry.npmjs.org/bindings
> contextify@0.1.4 install C:\Users\Matt Cashatt\node_modules\jquery\node_module
s\contextify
> node-gyp rebuild
C:\Users\Matt Cashatt\node_modules\jquery\node_modules\contextify>node "C:\Progr
am Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\b
in\node-gyp.js" rebuild
npm http 304 https://registry.npmjs.org/cssstyle
npm http 304 https://registry.npmjs.org/cssom
npm http 304 https://registry.npmjs.org/request
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYT
HON env variable.
gyp ERR! stack at failNoPython (C:\Program Files\nodejs\node_modules\npm\nod
e_modules\node-gyp\lib\configure.js:113:14)
gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node
-gyp\lib\configure.js:82:11
gyp ERR! stack at Object.oncomplete (fs.js:297:15)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modu
les\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\Matt Cashatt\node_modules\jquery\node_modules\contextify
gyp ERR! node -v v0.8.21
gyp ERR! node-gyp -v v0.8.4
gyp ERR! not ok
npm ERR! error rolling back Error: ENOTEMPTY, rmdir 'C:\Users\Matt Cashatt\node_
modules\jquery\node_modules\jsdom\node_modules\request\tests'
npm ERR! error rolling back jquery@1.8.3 { [Error: ENOTEMPTY, rmdir 'C:\Users\M
att Cashatt\node_modules\jquery\node_modules\jsdom\node_modules\request\tests']
npm ERR! error rolling back errno: 53,
npm ERR! error rolling back code: 'ENOTEMPTY',
npm ERR! error rolling back path: 'C:\\Users\\Matt Cashatt\\node_modules\\jque
ry\\node_modules\\jsdom\\node_modules\\request\\tests' }
npm ERR! contextify@0.1.4 install: `node-gyp rebuild`
npm ERR! `cmd "/c" "node-gyp rebuild"` failed with 1
npm ERR!
npm ERR! Failed at the contextify@0.1.4 install script.
npm ERR! This is most likely a problem with the contextify package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls contextify
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "jquery"
npm ERR! cwd C:\Users\Matt Cashatt
npm ERR! node -v v0.8.21
npm ERR! npm -v 1.2.11
npm ERR! code ELIFECYCLE
npm ERR! Error: ENOENT, lstat 'C:\Users\Matt Cashatt\node_modules\jquery\node_mo
dules\jsdom\node_modules\request\tests\test-pipes.js'
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-@googlegroups.com>
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "jquery"
npm ERR! cwd C:\Users\Matt Cashatt
npm ERR! node -v v0.8.21
npm ERR! npm -v 1.2.11
npm ERR! path C:\Users\Matt Cashatt\node_modules\jquery\node_modules\jsdom\node_
modules\request\tests\test-pipes.js
npm ERR! fstream_path C:\Users\Matt Cashatt\node_modules\jquery\node_modules\jsd
om\node_modules\request\tests\test-pipes.js
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! fstream_stack C:\Program Files\nodejs\node_modules\npm\node_modules\fst
ream\lib\writer.js:284:26
npm ERR! fstream_stack Object.oncomplete (fs.js:297:15)
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\Users\Matt Cashatt\npm-debug.log
npm ERR! not ok code 0
C:\Users\Matt Cashatt>
Run Code Online (Sandbox Code Playgroud)
看起来失败是由于缺少Python安装.好吧,我已经安装了Python,设置了变量,然后重新启动并仍然出错.
关于我缺少什么的任何线索?
ben*_*bia 428
如果您没有安装python以及所有node-gyp依赖项,只需使用管理员权限打开Powershell或Git Bash并执行:
npm install --global --production windows-build-tools
Run Code Online (Sandbox Code Playgroud)
然后安装包:
npm install --global node-gyp
Run Code Online (Sandbox Code Playgroud)
安装后,您将下载所有node-gyp依赖项,但仍需要环境变量.验证Python确实可以在正确的文件夹中找到:
C:\Users\ben\.windows-build-tools\python27\python.exe
Run Code Online (Sandbox Code Playgroud)
注意 - 它使用python 2.7而不是3.x,因为它不受支持
如果它没有呻吟,请继续创建您的(用户)环境变量:
setx PYTHON "%USERPROFILE%\.windows-build-tools\python27\python.exe"
Run Code Online (Sandbox Code Playgroud)
重新启动cmd,并验证变量是否存在,通过set PYTHON该变量返回变量
最后重新申请 npm install <module>
aba*_*ert 127
您的问题是您没有设置环境变量.
错误清楚地说明了这一点:
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
Run Code Online (Sandbox Code Playgroud)
在你的评论中,你说你这样做了:
set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib
Run Code Online (Sandbox Code Playgroud)
这很好,但是没有设置PYTHON变量,它设置PYTHONPATH变量.
同时,仅使用该set命令仅影响当前cmd会话.如果你之后重新启动,就像你说的那样,你最终会得到一个cmd没有设置该变量的全新会话.
有几种方法可以永久地设置环境变量 - 最简单的方法是在XP中的系统控制面板中,这在Vista中当然不同,在7中再次不同,在8中再次不同,但您可以谷歌搜索它.
或者,只需set在npm命令之前执行,而无需重新启动.
您可以通过执行配置脚本尝试执行的完全相同的操作来测试您是否做得对:在运行之前npm,请尝试运行%PYTHON%.如果你做得对,你会得到一个Python解释器(你可以立即退出).如果您收到错误,则表示您没有做错.
这有两个问题:
set PYTHON=%PYTHON%;D:\Python
Run Code Online (Sandbox Code Playgroud)
首先,你设置PYTHON到;D:\Python.这个额外的分号适用于以分号分隔的路径列表,例如PATH或PYTHONPATH,但不适用于单个值PYTHON.同样,当您想要将另一个路径添加到路径列表而不是单个值时,您希望为现有值添加新值.所以,你只是想要set PYTHON=D:\Python.
其次,D:\Python不是Python解释器的路径.它就像D:\Python\Python.exe,或者D:\Python\bin\Python.exe.找到正确的路径,确保它自己工作(例如,键入D:\Python\bin\Python.exe并确保获得Python解释器),然后设置变量并使用它.
所以:
set PYTHON=D:\Python\bin\Python.exe
Run Code Online (Sandbox Code Playgroud)
或者,如果要使其永久化,请在"控制面板"中执行等效操作.
小智 14
这是一本为我解决了很多这些问题的指南.
http://www.steveworkman.com/node-js/2012/installing-jsdom-on-windows/
我特别记得python版本很重要.确保安装2.7.3而不是3.
小智 11
对我来说,在安装带有以下注释的Windows-Build-tools之后
npm --add-python-to-path='true' --debug install --global windows-build-tools
Run Code Online (Sandbox Code Playgroud)
运行下面的代码
npm config set python "%USERPROFILE%\.windows-build-tools\python27\python.exe"
Run Code Online (Sandbox Code Playgroud)
工作了。
其中一个和/或多个应该有所帮助:
添加C:\Python27\到您的PATH变量(考虑到您在此目录中安装了Python)
如何设置PATHenv变量:http://www.computerhope.com/issues/ch000549.htm
设置变量后重新启动控制台和/或Windows.
在与上面相同的部分("环境变量")中,添加具有名称PYTHON和值的新变量C:\Python27\python.exe
在设置变量后重新启动控制台和/或Windows.
在管理员模式下打开Windows命令行(cmd).
将目录更改为Python安装路径:
为某些安装创建符号链接:cd C:\Python27mklink python2.7.exe python.exe
请注意,您应该使用Python 2.x,而不是3.x来运行node-gyp基于安装!
下面的文字说的是Unix,但Windows版本也需要Python 2.x:
You can install with npm:
$ npm install -g node-gyp
You will also need to install:
On Unix:
python (v2.7 recommended, v3.x.x is not supported)
make
A proper C/C++ compiler toolchain, like GCC
Run Code Online (Sandbox Code Playgroud)
本文也可能有所帮助:https://github.com/nodejs/node-gyp#installation
我有同样的问题,这些答案都没有帮助.在我的情况下,PYTHON变量设置正确.然而,python安装得太深,即路径太长.所以,我做了以下事情:
就是这样!
我在尝试安装 node-sass@4.9.4时遇到了同样的挑战。
在查看了当前的官方文档并阅读了上面的答案后,我注意到您可能不必安装 node-gyp 或安装 windows-build 工具。这就是它所说的,这里是关于在 windows 上安装 node-gyp。记住 node-gyp 参与了 node-sass 的安装过程。而且您实际上不必重新安装另一个 python 版本。
这是救星,配置“npm”在安装任何需要构建工具的包时应该查找的python路径。
C:\> npm config set python /Python36/python
Run Code Online (Sandbox Code Playgroud)
我已经在 windows-7 上安装了 python3.6.3。
这是让 NPM 为您做所有事情的最简单方法
npm --add-python-to-path='true' --debug install --global windows-build-tools
Run Code Online (Sandbox Code Playgroud)
TL;DR 使用名称 python2.7.exe 制作 python.exe 的副本或别名
我的 python 2.7 安装为
D:\app\Python27\python.exe
无论我如何设置(和验证)PYTHON 环境变量,我总是遇到此错误:
吉普错误!堆栈错误:找不到 Python 可执行文件“python2.7”,您可以设置 PYTHON 环境变量。 吉普错误!堆栈在 failNoPython (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:103:14)
这样做的原因是在 node-gyp 的 configure.js 中,python 可执行文件被解析为:
var python = gyp.opts.python || process.env.PYTHON || 'python'
结果证明 gyp.opts.python 的值为 'python2.7',因此覆盖了 process.env.PYTHON。
我通过为 python.exe 可执行文件创建一个别名来解决这个问题,名称为 node-gyp 正在寻找:
D:\app\Python27>mklink python2.7.exe python.exe
您需要此操作的管理员权限。
以下内容从命令行以管理员身份对我有用:
安装 windows-build-tools(这可能需要 15-20 分钟):
npm --add-python-to-path='true' --debug install --global windows-build-tools
Run Code Online (Sandbox Code Playgroud)
添加/更新环境变量:
setx PYTHON "%USERPROFILE%\.windows-build-tools\python27\python.exe"
Run Code Online (Sandbox Code Playgroud)
安装节点gyp:
npm install --global node-gyp
Run Code Online (Sandbox Code Playgroud)
将 exe 文件的名称从 Python 更改为 Python2.7。
C:\Users\username\.windows-build-tools\python27\Python2.7
Run Code Online (Sandbox Code Playgroud)
npm install module_name --save
小智 5
有一些解决此问题的解决方案:1)以“管理员”身份运行命令提示符。
如果第一个解决方案不能解决您的问题,请尝试以下方法:
2)在管理员粘贴以下代码行的情况下打开命令提示符,然后按Enter键:
npm install --global --production windows-build-tools
Run Code Online (Sandbox Code Playgroud)
我忍不住要提到这一点。如果您使用Python3和淋巴结GYP失败,那么我很伤心地告诉你节点GYP目前不支持python3。
这是给你的链接:https : //github.com/nodejs/node-gyp/issues/1268 https://github.com/nodejs/node-gyp/issues/193
小智 5
这有所帮助:https : //www.npmjs.com/package/node-gyp
我按照以下步骤操作:
npm install -g node-gyp
Run Code Online (Sandbox Code Playgroud)
然后:
npm install --global --production windows-build-tools
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
309837 次 |
| 最近记录: |