¿Cómo usar una versión diferente de python durante la instalación de NPM?


Tengo instalado el acceso de terminal a un VPS que ejecuta centos 5.9 y python 2.4.3 por defecto. También instalé python 2.7.3 a través de estos comandos: (Usé make altinstall en lugar de 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

Luego instalé node.js de la fuente a través de estos comandos:

python2.7 ./configure
make
make install

El problema es, cuando uso npm install e intento instalar un nodo.paquete js que requiere python > 2.4.3 Obtengo este 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

¿Cómo debería "pasar el interruptor python python para apuntar a Python >= v2.5.0"?

Author: Cœur, 2013-12-08

5 answers

Puede usar la opción --python para npm de esta manera:

npm install --python=python2.7

O configurarlo para que se use siempre:

npm config set python python2.7

Npm a su vez pasará esta opción a node-gyp cuando sea necesario.

(nota: Yo soy el que abrió un problema en Github para que esto se incluya en los documentos, ya que había tantas preguntas al respecto; -))

 415
Author: ack,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-03-16 06:40:18

Establezca python en python2. 7 antes de ejecutar npm install

Linux:

export PYTHON=python2.7

Ventanas:

set PYTHON=python2.7
 49
Author: Sandtears Kirisame,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-23 21:31:23

Para los usuarios de Windows algo como esto debería funcionar:

PS C:\angular> npm install --python=C:\Python27\python.exe
 30
Author: Dave L.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-15 18:32:53

Ok, así que ya has encontrado una solución. Solo quería compartir lo que me ha sido útil tantas veces;

He creado setpy2 alias que me ayuda a cambiar python.

alias setpy2="mkdir -p /tmp/bin; ln -s `which python2.7` /tmp/bin/python; export PATH=/tmp/bin:$PATH"

Ejecute setpy2 antes de ejecutar npm install. El conmutador permanece en efecto hasta que salga de la terminal, después python se vuelve a establecer como predeterminado del sistema.

También puede hacer uso de esta técnica para cualquier otro comando/herramienta.

 7
Author: vmx,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-08 19:14:30

Para un uso rápido de una vez esto funciona, npm install python python="c:\python27"

 0
Author: MPV,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-07 04:37:20