在Windows上运行Python以获取Node.js依赖项

python Node.js

Gil

2020-03-23

我正在进入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>

看来失败是由于缺少Python安装造成的。好了,我已经安装了Python,设置了变量,然后重新启动,仍然是错误。

关于我所缺少的任何线索吗?

第2661篇《在Windows上运行Python以获取Node.js依赖项》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

16个回答
凯西里 2020.03.23

对我来说,这些步骤解决了这个问题:

1-以管理员身份运行此cmd:

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

2-然后npm rebuild在第一步完成后运行(尤其是完成python 2.7安装,这是问题的主要原因)

小卤蛋Green小哥 2020.03.23

对我来说,问题是我使用的是节点的最新版本,而不是LTS稳定版本并建议大多数用户使用的版本。
使用LTS版本解决了该问题。
您可以从这里下载:

LTS版本

当前最新版本

Gil 2020.03.23

例子:pg_config不可执行/错误node-gyp

解决方案:在Windows上,只需尝试添加PATH Env-> C:\ Program Files \ PostgreSQL \ 12 \ bin

为我工作,现在我可以使用pg-promise例如npm或其他依赖项。

泡芙 2020.03.23

如果您尝试在Cygwin上使用此功能,则需要按照答案中的说明进行操作(这是Cygwin如何对待Windows符号链接的问题。)

路易番长 2020.03.23

这是正确的命令:set path =%path%; C:\ Python34 [替换为正确的python安装路径]

我有同样的问题,我只是这样解决了。

正如其他人指出的那样,这是易失性配置,仅适用于当前的cmd会话,并且(显然)您必须在运行npm install之前设置路径。

我希望这有帮助。

神无 2020.03.23

糟糕!配置错误gyp ERR!错误:找不到Python可执行文件“ python”,您可以设置PYT HON env变量。

无需重新安装,此异常由node-gyp脚本引发,然后尝试重新构建。设置环境变量就足够了,就像我所做的那样:

SET PYTHON=C:\work\_env\Python27\python.exe
Eva十三 2020.03.23

正确的方法是1)从此处下载并安装python 2.7.14 2)从这里为python设置环境变量

完成了!

注意:请相应地设置环境变量。我在这里为窗户回答。

老丝阿飞 2020.03.23

为什么不在这里下载python安装程序当您检查路径安装时,它将为您工作

伽罗理查德 2020.03.23

在尝试安装node-sass@4.9.4时遇到了同样的挑战

在查看了当前的官方文档并阅读了上面的答案之后,我注意到您不一定必须安装node-gyp或Windows构建工具。这就是它所说的,关于在Windows上安装node-gyp请记住,node-gyp参与了node-sass的安装过程。而且,您实际上不必重新安装另一个python版本。

这是救星,在安装任何需要构建工具的软件包时配置“ npm”应查找的python路径。

C:\> npm config set python /Python36/python

我已经在Windows-7上安装了python3.6.3。

GO猿 2020.03.23

我忍不住提这个。如果您使用Python3和淋巴结GYP失败,那么我很伤心地告诉你节点GYP目前不支持python3。

这是给您的链接:https : //github.com/nodejs/node-gyp/issues/1268 https://github.com/nodejs/node-gyp/issues/193

null 2020.03.23

有一些解决此问题的方法:1)以“管理员”身份运行命令提示符。

如果第一个解决方案不能解决您的问题,请尝试以下方法:

2)在管理员粘贴以下代码行的情况下打开命令提示符,然后按Enter键:

npm install --global --production windows-build-tools
小胖Gil 2020.03.23

这有所帮助:https : //www.npmjs.com/package/node-gyp

我遵循以下步骤:

npm install -g node-gyp

然后:

npm install --global --production windows-build-tools
斯丁 2020.03.23

如果您尚未安装python以及所有node-gyp依赖项,只需使用管理员权限打开Powershell或Git Bash并执行:

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

然后安装该软件包:

npm install --global node-gyp

安装后,将下载所有的node-gyp依赖项,但仍需要环境变量。确实在正确的文件夹中找到了验证Python:

C:\Users\ben\.windows-build-tools\python27\python.exe 

注意-它使用python 2.7而不是3.x,因为它不受支持

如果没有抱怨,请继续创建您的(用户)环境变量:

setx PYTHON "%USERPROFILE%\.windows-build-tools\python27\python.exe"

重新启动cmd,并验证变量是否存在set PYTHON,应通过该变量返回变量

最后重新申请 npm install <module>

Stafan村村 2020.03.23

我遇到了同样的问题,这些答案都没有帮助。在我的情况下,PYTHON变量设置正确。但是python安装得太深,即路径太长。因此,我做了以下工作:

  1. 将python重新安装到c:\ python
  2. 将环境变量PYTHON设置为C:\ python \ python.exe

就是这样!

逆天神乐 2020.03.23

这是为我解决了许多这些问题的指南。

http://www.steveworkman.com/node-js/2012/installing-jsdom-on-windows/

我特别记得python版本很重要。确保安装2.7.3而不是3。

樱小胖Mandy 2020.03.23

其中一个和/或多个应该帮助:

  1. Add C:\Python27\ to your PATH variable (considering you have Python installed in this directory)
    How to set PATH env variable: http://www.computerhope.com/issues/ch000549.htm
    Restart your console and/or Windows after setting variable.

  2. In the same section as above ("Environment Variables"), add new variable with name PYTHON and value C:\Python27\python.exe
    Restart your console and/or Windows after setting variable.

  3. Open Windows command line (cmd) in Admin mode.
    Change directory to your Python installation path: cd C:\Python27
    Make symlink needed for some installations: mklink python2.7.exe python.exe

Please note that you should have Python 2.x, NOT 3.x, to run node-gyp based installations!

以下文字是关于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

本文可能也有帮助:https : //github.com/nodejs/node-gyp#installation

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android