问题:在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
您可以使用--python
npm选项,如下所示:
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