在 Windows 上为 Node.js 依赖项运行 Python [英] Running Python on Windows for Node.js dependencies

查看:49
本文介绍了在 Windows 上为 Node.js 依赖项运行 Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Node.js 代码库,这要求我通过 NPM(即 jQuery)下载一些依赖项.

I am getting into a Node.js codebase which requires that I download a few dependencies via NPM, namely jQuery.

在尝试运行 npm install jquery 时,我不断收到此错误:

In attempting to run npm install jquery, I keep getting this error:

Your environment has been set up for using Node.js 0.8.21 (x64) and NPM

C:UsersMatt 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:UsersMatt Cashatt
ode_modulesjquery
ode_module
scontextify
> node-gyp rebuild


C:UsersMatt Cashatt
ode_modulesjquery
ode_modulescontextify>node "C:Progr
am Files
odejs
ode_modules
pmin
ode-gyp-bin\....
ode_modules
ode-gyp
in
ode-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
odejs
ode_modules
pm
od
e_modules
ode-gyplibconfigure.js:113:14)
gyp ERR! stack     at C:Program Files
odejs
ode_modules
pm
ode_modules
ode
-gyplibconfigure.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:UsersMatt Cashatt
ode_modulesjquery
ode_modulescontextify
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:UsersMatt Cashatt
ode_
modulesjquery
ode_modulesjsdom
ode_modules
equest	ests'
npm ERR! error rolling back  jquery@1.8.3 { [Error: ENOTEMPTY, rmdir 'C:UsersM
att Cashatt
ode_modulesjquery
ode_modulesjsdom
ode_modules
equest	ests']
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:UsersMatt 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:UsersMatt Cashatt
ode_modulesjquery
ode_mo
dulesjsdom
ode_modules
equest	ests	est-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:UsersMatt Cashatt
npm ERR! node -v v0.8.21
npm ERR! npm -v 1.2.11
npm ERR! path C:UsersMatt Cashatt
ode_modulesjquery
ode_modulesjsdom
ode_
modules
equest	ests	est-pipes.js
npm ERR! fstream_path C:UsersMatt Cashatt
ode_modulesjquery
ode_modulesjsd
om
ode_modules
equest	ests	est-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
odejs
ode_modules
pm
ode_modulesfst
reamlibwriter.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:UsersMatt Cashatt
pm-debug.log
npm ERR! not ok code 0

C:UsersMatt Cashatt>

失败的原因似乎是缺少 Python 安装.好吧,我已经安装了 Python,设置了变量,然后重新启动,仍然是错误.

It looks like the failure is due to a missing Python installation. Well, I have installed Python, set the variable, and rebooted and still the error.

任何关于我遗漏了什么的线索?

Any clue as to what I am missing?

推荐答案

你的问题是你没有设置环境变量.

Your problem is that you didn't set the environment variable.

错误清楚地说明了这一点:

The error clearly says this:

gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.

并且在您的评论中,您说您这样做了:

And in your comment, you say you did this:

set PYTHONPATH=%PYTHONPATH%;C:My_python_lib

这很好,但它不会设置 PYTHON 变量,而是设置 PYTHONPATH 变量.

That's nice, but that doesn't set the PYTHON variable, it sets the PYTHONPATH variable.

同时,仅使用 set 命令只会影响当前的 cmd 会话.如果您在此之后重新启动,正如您所说的那样,您最终会得到一个全新的 cmd 会话,其中没有设置该变量.

Meanwhile, just using the set command only affects the current cmd session. If you reboot after that, as you say you did, you end up with a whole new cmd session that doesn't have that variable set in it.

有几种方法可以永久设置环境变量——最简单的是在 XP 中的系统控制面板中,当然在 Vista 中不同,在 7 中再次不同,在 8 中再次不同,但你可以谷歌搜索.

There are a few ways to set environment variables permanently—the easiest is in the System Control Panel in XP, which is of course different in Vista, different again in 7, and different again in 8, but you can google for it.

或者,只需在 npm 命令之前执行 set,中间无需重新启动.

Alternatively, just do the set right before the npm command, without rebooting in between.

您可以通过执行配置脚本试图做的完全相同的事情来测试您是否做对了:在运行 npm 之前,尝试运行 %PYTHON%.如果你做对了,你会得到一个 Python 解释器(你可以立即退出).如果出现错误,说明您没有做对.

You can test whether you've done things right by doing the exact same thing the config script is trying to do: Before running npm, try running %PYTHON%. If you've done it right, you'll get a Python interpreter (which you can immediately quit). If you get an error, you haven't done it right.

这有两个问题:

set PYTHON=%PYTHON%;D:Python

首先,您将 PYTHON 设置为 ;D:Python.额外的分号适用于以分号分隔的路径列表,例如 PATHPYTHONPATH,但不适用于像 PYTHON 这样的单个值.同样,当您想要将另一个路径添加到路径列表而不是单个值时,向现有值添加新值是您想要的.所以,你只需要 set PYTHON=D:Python.

First, you're setting PYTHON to ;D:Python. That extra semicolon is fine for a semicolon-separated list of paths, like PATH or PYTHONPATH, but not for a single value like PYTHON. And likewise, adding a new value to the existing value is what you want when you want to add another path to a list of paths, but not for a single value. So, you just want set PYTHON=D:Python.

其次,D:Python 不是 Python 解释器的路径.它类似于 D:PythonPython.exeD:PythoninPython.exe.找到正确的路径,确保它自己工作(例如,输入 D:PythoninPython.exe 并确保你得到一个 Python 解释器),然后设置变量并使用它.

Second, D:Python is not the path to your Python interpreter. It's something like D:PythonPython.exe, or D:PythoninPython.exe. Find the right path, make sure it works on its own (e.g., type D:PythoninPython.exe and make sure you get a Python interpreter), then set the variable and use it.

所以:

set PYTHON=D:PythoninPython.exe

或者,如果您想将其永久化,请在控制面板中执行相同的操作.

Or, if you want to make it permanent, do the equivalent in the Control Panel.

这篇关于在 Windows 上为 Node.js 依赖项运行 Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆