如何在 NPM 安装期间使用不同版本的 python? [英] How to use a different version of python during NPM install?

查看:23
本文介绍了如何在 NPM 安装期间使用不同版本的 python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过终端访问运行 centos 5.9 并安装默认 python 2.4.3 的 VPS.我还通过这些命令安装了 python 2.7.3:(我使用了 make altinstall 而不是 make install)

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

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

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

python2.7 ./configure
make
make install

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

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

我应该如何传递 --python 开关以指向 Python >= v2.5.0"?

推荐答案

你可以像这样使用 --python 选项来 npm:

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 会在需要时将此选项传递给 node-gyp.

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

(注意:我是在 Github 上提出问题并将其包含在文档中的人,因为关于它的问题太多了;-))

(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 ;-) )

这篇关于如何在 NPM 安装期间使用不同版本的 python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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