如何在NPM安装期间使用不同版本的python?

2024-05-16 21:42:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我可以通过终端访问运行centos 5.9和默认python 2.4.3的VPS。我还通过以下命令安装了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“?


Tags: install命令gtmodulesnodenpmmakestack
3条回答

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

Linux系统:

export PYTHON=python2.7

窗口:

set PYTHON=python2.7

您可以使用--python选项来npm,如下所示:

npm install --python=python2.7

或将其设置为始终使用:

npm config set python python2.7

当需要时,Npm将依次将此选项传递给node gyp。

(注意:我是在Github上打开了一个问题并将其包含在文档中的人,因为有很多关于它的问题;-))

对于Windows用户,应该可以这样做:

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

相关问题 更多 >