标签归档:npm

在NPM安装期间如何使用其他版本的python?

问题:在NPM安装期间如何使用其他版本的python?

我可以通过终端访问运行centos 5.9的VPS,并安装了默认的python 2.4.3。我还通过以下命令安装了python 2.7.3 :(我使用make altinstall代替make install

wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar -xf Python-2.7.3.tgz
cd Python-2.7.3
./configure
make
make altinstall

然后我通过以下命令从源代码安装了node.js:

python2.7 ./configure
make
make install

问题是,当我使用npm install并尝试安装需要python> 2.4.3的node.js软件包时,出现此错误:

gyp ERR! configure error
gyp ERR! stack Error: Python executable "python" is v2.4.3, which is not supported by gyp.
gyp ERR! stack You can pass the --python switch to point to Python >= v2.5.0 & < 3.0.0.
gyp ERR! stack     at failPythonVersion (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:125:14)
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:114:9

我应该如何“通过–python开关以指向Python> = v2.5.0”

I have terminal access to a VPS running centos 5.9 and default python 2.4.3 installed. I also installed python 2.7.3 via these commands: (I used make altinstall instead of make install)

wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar -xf Python-2.7.3.tgz
cd Python-2.7.3
./configure
make
make altinstall

then I installed node.js from source via these commands:

python2.7 ./configure
make
make install

The problem is, when I use npm install and try to install a node.js package which requires python > 2.4.3 I get this error:

gyp ERR! configure error
gyp ERR! stack Error: Python executable "python" is v2.4.3, which is not supported by gyp.
gyp ERR! stack You can pass the --python switch to point to Python >= v2.5.0 & < 3.0.0.
gyp ERR! stack     at failPythonVersion (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:125:14)
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:114:9

how should I “pass the –python switch to point to Python >= v2.5.0”?


回答 0

您可以使用--pythonnpm选项,如下所示:

npm install --python=python2.7

或将其设置为始终使用:

npm config set python python2.7

Npm会在需要时依次将此选项传递给node-gyp。

(注意:我是在Github上发布一个问题将此文档包含在文档中的人,因为对此有太多问题;-))

You can use --python option to npm like so:

npm install --python=python2.7

or set it to be used always:

npm config set python python2.7

Npm will in turn pass this option to node-gyp when needed.

(note: I’m the one who opened an issue on Github to have this included in the docs, as there were so many questions about it ;-) )


回答 1

在运行npm install之前将python设置为python2.7

Linux:

export PYTHON=python2.7

视窗:

set PYTHON=python2.7

set python to python2.7 before running npm install

Linux:

export PYTHON=python2.7

Windows:

set PYTHON=python2.7

回答 2

对于Windows用户,类似这样的方法应该起作用:

PS C:\angular> npm install --python=C:\Python27\python.exe

For Windows users something like this should work:

PS C:\angular> npm install --python=C:\Python27\python.exe

回答 3

好的,所以您已经找到了解决方案。只想分享对我有用很多次的东西;

我创建了setpy2别名,可以帮助我切换python。

alias setpy2="mkdir -p /tmp/bin; ln -s `which python2.7` /tmp/bin/python; export PATH=/tmp/bin:$PATH"

执行setpy2之前运行npm install。该开关将一直有效,直到您退出终端为止,之后python将其设置回系统默认值。

您也可以将这种技术用于任何其他命令/工具。

Ok, so you’ve found a solution already. Just wanted to share what has been useful to me so many times;

I have created setpy2 alias which helps me switch python.

alias setpy2="mkdir -p /tmp/bin; ln -s `which python2.7` /tmp/bin/python; export PATH=/tmp/bin:$PATH"

Execute setpy2 before you run npm install. The switch stays in effect until you quit the terminal, afterwards python is set back to system default.

You can make use of this technique for any other command/tool as well.


回答 4

为了快速使用它,npm install –python =“ c:\ python27”

for quick one time use this works, npm install –python=”c:\python27″


回答 5

如果您在路径上没有python或想指定目录,此方法效果更好:

//for Windows
npm config set python C:\Python27\python.exe

//for Linux
npm config set python /usr/bin/python27

This one works better if you don’t have the python on path or want to specify the directory :

//for Windows
npm config set python C:\Python27\python.exe

//for Linux
npm config set python /usr/bin/python27

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

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

我正在进入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,设置了变量,然后重新启动,仍然是错误。

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

I am getting into a Node.js codebase which requires that I download a few dependencies via NPM, namely 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:\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>

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?


回答 0

您的问题是您没有设置环境变量。

该错误清楚地表明:

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

在评论中,您说您这样做:

set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib

很好,但是没有设置PYTHON变量,而是设置了PYTHONPATH变量。


同时,仅使用set命令只会影响当前cmd会话。如果重新启动之后(如您所说的那样),最终将导致一个全新的cmd会话,其中未设置该变量。

有几种方法可以永久性地设置环境变量-最简单的方法是在XP的系统控制面板中,当然在Vista中有所不同,在7中又有所不同,在8中又有所不同,但是您可以用google搜索。

或者,只需setnpm命令前执行正确操作,而无需在两者之间重新引导。


您可以通过执行与配置脚本完全相同的操作来测试您是否正确完成了操作:在运行之前npm,请尝试运行%PYTHON%。如果做对了,您将获得一个Python解释器(您可以立即退出)。如果遇到错误,则说明您做错了。


这有两个问题:

set PYTHON=%PYTHON%;D:\Python

首先,您将设置PYTHON;D:\Python。多余的分号适用于以分号分隔的路径列表(例如PATHor)PYTHONPATH,但不适用于单个值(例如)PYTHON。同样,当您要向路径列表中添加另一个路径而不是为单个值添加新值时,则需要在现有值上添加一个新值。因此,您只需要set PYTHON=D:\Python

其次,D:\Python不是您的Python解释器的路径。就像D:\Python\Python.exeD:\Python\bin\Python.exe。找到正确的路径,确保它可以独立运行(例如,键入D:\Python\bin\Python.exe并确保您拥有Python解释器),然后设置变量并使用它。


所以:

set PYTHON=D:\Python\bin\Python.exe

或者,如果要使其永久不变,请在“控制面板”中执行等效操作。

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

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


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.

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.

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


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.


There are two problems with this:

set PYTHON=%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.

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


So:

set PYTHON=D:\Python\bin\Python.exe

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


回答 1

如果您尚未安装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>

If you haven’t got python installed along with all the node-gyp dependencies, simply open Powershell or Git Bash with administrator privileges and execute:

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

and then to install the package:

npm install --global node-gyp

once installed, you will have all the node-gyp dependencies downloaded, but you still need the environment variable. Validate Python is indeed found in the correct folder:

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

Note – it uses python 2.7 not 3.x as it is not supported

If it doesn’t moan, go ahead and create your (user) environment variable:

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

restart cmd, and verify the variable exists via set PYTHON which should return the variable

Lastly re-apply npm install <module>


回答 2

对我来说,安装带有以下注释的Windows-build-tools之后

npm --add-python-to-path='true' --debug install --global windows-build-tools

运行下面的代码

npm config set python "%USERPROFILE%\.windows-build-tools\python27\python.exe"

工作了。

For me after installing windows-build-tools with the below comment

npm --add-python-to-path='true' --debug install --global windows-build-tools

running the code below

npm config set python "%USERPROFILE%\.windows-build-tools\python27\python.exe"

has worked.


回答 3

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

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

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

Here is a guide that resolved a lot of these issues for me.

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

I remember in particular the python version as important. Make sure you install 2.7.3 instead of 3’s.


回答 4

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

  1. 添加C:\Python27\PATH变量中(考虑到此目录中已安装Python)
    如何设置环境PATH变量:http : //www.computerhope.com/issues/ch000549.htm
    设置变量后,重新启动控制台和/或Windows。

  2. 在与上述相同的部分(“环境变量”)中,添加具有名称PYTHON和值的新C:\Python27\python.exe
    变量。设置变量后,重新启动控制台和/或Windows。

  3. 在Admin模式下打开Windows命令行(cmd)。 将目录更改为您的Python安装路径: 进行某些安装需要符号链接:
    cd C:\Python27
    mklink python2.7.exe python.exe

请注意,您应该具有Python 2.x而非NOT 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

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

One and/or multiple of those should help:

  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!

The text below says about Unix, but Windows version also requires 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

This article may also help: https://github.com/nodejs/node-gyp#installation


回答 5

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

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

就是这样!

I had the same issue and none of these answers did help. In my case PYTHON variable was set correctly. However python was installed too deep, i.e. has too long path. So, I did the following:

  1. reinstalled python to c:\python
  2. set environmental variable PYTHON to C:\python\python.exe

And that’s it!


回答 6

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

我遵循以下步骤:

npm install -g node-gyp

然后:

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

This helped: https://www.npmjs.com/package/node-gyp

I followed these steps:

npm install -g node-gyp

then:

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

回答 7

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

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

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

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

there are some solution to solve this issue : 1 ) run your command prompt as “administrator”.

if first solution doesn’t solve your problem try this one :

2 ) open a command prompt as administrator paste following line of code and hit enter :

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

回答 8

TL; DR使用名称python2.7.exe复制python.exe或别名

我的python 2.7安装为

D:\ app \ Python27 \ python.exe

无论我如何设置(并验证)PYTHON env变量,我总是会收到此错误:

糟糕!错误:找不到Python可执行文件“ python2.7”,您可以设置PYTHON env变量。
糟糕!在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。

我通过为名称为node-gyp的python.exe可执行文件创建别名来解决此问题:

D:\app\Python27>mklink python2.7.exe python.exe

您需要此操作的管理员权限。

TL;DR Make a copy or alias of your python.exe with name python2.7.exe

My python 2.7 was installed as

D:\app\Python27\python.exe

I always got this error no matter how I set (and verified) PYTHON env variable:

gyp ERR! stack Error: Can't find Python executable "python2.7", you can set the PYTHON env variable.
gyp ERR! stack     at failNoPython (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:103:14)

The reason for this was that in node-gyp’s configure.js the python executable was resolved like:

var python = gyp.opts.python || process.env.PYTHON || 'python'

And it turned out that gyp.opts.python had value ‘python2.7’ thus overriding process.env.PYTHON.

I resolved this by creating an alias for python.exe executable with name node-gyp was looking for:

D:\app\Python27>mklink python2.7.exe python.exe

You need admin rights for this operation.


回答 9

以下内容以管理员身份在命令行为我工作:

安装Windows-Build-tools(这可能需要15-20分钟):

 npm --add-python-to-path='true' --debug install --global windows-build-tools

添加/更新环境变量:

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

安装node-gyp:

npm install --global node-gyp

将exe文件的名称从Python更改为Python2.7。

C:\Users\username\.windows-build-tools\python27\Python2.7

npm install module_name --save

The following worked for me from the command line as admin:

Installing windows-build-tools (this can take 15-20 minutes):

 npm --add-python-to-path='true' --debug install --global windows-build-tools

Adding/updating the environment variable:

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

Installing node-gyp:

npm install --global node-gyp

Changing the name of the exe file from Python to Python2.7.

C:\Users\username\.windows-build-tools\python27\Python2.7

npm install module_name --save


回答 10

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

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

i can’t help but to mention this. If you’re using Python3 and failing with node-gyp, then i’m sad to tell you node-gyp currently doesn’t support python3.

Here is a link for you: https://github.com/nodejs/node-gyp/issues/1268 https://github.com/nodejs/node-gyp/issues/193


回答 11

这是让NPM为您做所有事情的最简单方法

npm --add-python-to-path='true' --debug install --global windows-build-tools

This is most easiest way to let NPM do everything for you

npm --add-python-to-path='true' --debug install --global windows-build-tools

回答 12

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

完成!

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

The right way is 1) Download and Install python 2.7.14 from here. 2) Set environment variable for python from here.

done!

note: Please set environment variable accordingly. I answered here for windows.


回答 13

在尝试安装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。

I met the same challenge while trying to install node-sass@4.9.4.

And after looking at the current official documentation, and having read the answers above, i noticed that you might not necessarily have to install node-gyp nor install windows-build tools. This is what it says, here about installing node-gyp on windows. Remember node-gyp is involved in the installation process of node-sass. And you don’t really have to re-install another python version.

This is the savior, configure the python path that “npm” should look for while installing any packages that require build-tools.

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

I had installed python3.6.3, on windows-7, there.


回答 14

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

Why not downloading the python installer here ? It make the work for you when you check the path installation


回答 15

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

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

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

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

For me, these steps fixed the issue:

1- Running this cmd as admin:

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

2- Then running npm rebuild after the 1st step is completed (especially completing the python 2.7 installation, which was the main cause of the issue)


回答 16

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

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

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

我希望这有帮助。

Here is the correct command: set path=%path%;C:\Python34 [Replace with the correct path of your python installation]

I had the same problem and I just solved this like that.

As some other people pointed out, this is volatile configuration, it only works for the current cmd session, and (obviously) you have to set your path before you run npm install.

I hope this helps.


回答 17

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

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

SET PYTHON=C:\work\_env\Python27\python.exe

gyp ERR! configure error gyp ERR! stack Error: Can’t find Python executable “python”, you can set the PYT HON env variable.

Not necessary to reinstall, this exception throw by node-gyp script, then try to rebuild. It’s enough setup environment variable like in my case I did:

SET PYTHON=C:\work\_env\Python27\python.exe

回答 18

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

If you’re trying to use this on Cygwin, then you need to follow the instructions in this answer. (It’s a problem how Cygwin treats Windows symlinks.)


回答 19

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

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

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

Example : pg_config not executable / error node-gyp

Solution : On windows just try to add PATH Env -> C:\Program Files\PostgreSQL\12\bin

Work for me, Now i can use npm i pg-promise for example or other dependencies.


回答 20

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

LTS版本

当前最新版本

For me, The issue was that i was using node’s latest version and not the LTS version which is the stable version and recommended for most users.
Using the LTS Version solved the issue.
You can download from here :

LTS Version

Current Latest Version