How to use a different version of python during NPM install?
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 ;-) )
set python to python2.7 before running npm install
Linux:
export PYTHON=python2.7
Windows:
set PYTHON=python2.7
For Windows users something like this should work:
PS C:\angular> npm install --python=C:\Python27\python.exe
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
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.