How to use a different version of python during NPM install?

后端 未结 6 652
無奈伤痛
無奈伤痛 2020-12-07 06:39

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

相关标签:
6条回答
  • 2020-12-07 07:10

    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.

    0 讨论(0)
  • 2020-12-07 07:12

    set python to python2.7 before running npm install

    Linux:

    export PYTHON=python2.7
    

    Windows:

    set PYTHON=python2.7
    
    0 讨论(0)
  • 2020-12-07 07:19

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

    0 讨论(0)
  • 2020-12-07 07:27

    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
    
    0 讨论(0)
  • 2020-12-07 07:29

    for quick one time use this works, npm install --python="c:\python27"

    0 讨论(0)
  • 2020-12-07 07:30

    For Windows users something like this should work:

    PS C:\angular> npm install --python=C:\Python27\python.exe
    
    0 讨论(0)
提交回复
热议问题