web-dev-qa-db-fra.com

"Impossible de trouver l'exécutable Python ..." - L'installation de NPM se bloque

J'utilise "npm install" pour télécharger et compiler toutes les dépendances d'une petite application node.js que j'ai écrite. Le fichier "package.json" que j'utilise est correct et contient toutes les informations nécessaires.

L'un des paquets à installer a "node-gyp" comme dépendance, donc j'ai déjà installé le paquet "python2".

Maintenant, à un moment donné, je commence à recevoir des messages d'erreur:

> node-gyp rebuild

gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at failNoPython (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:103:14)
gyp ERR! stack     at /usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:42:11
gyp ERR! stack     at F (/usr/lib/node_modules/npm/node_modules/which/which.js:40:25)
gyp ERR! stack     at E (/usr/lib/node_modules/npm/node_modules/which/which.js:43:29)
gyp ERR! stack     at /usr/lib/node_modules/npm/node_modules/which/which.js:54:16
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:99:15)
gyp ERR! System Linux 3.18.9-200.fc21.x86_64
gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /srv/visitor/node_modules/phantom/node_modules/dnode/node_modules/weak
gyp ERR! node -v v0.12.1
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok
npm WARN optional dep failed, continuing [email protected]

Le problème semble être qu'une variable d'environnement est manquante. 

Est-ce que quelqu'un peut-il me montrer la bonne direction? Peu importe où je cherche sur Internet, il n'est pas fait mention d'une variable "PYTHON", seulement de "PYTHONPATH" et d'autres semblables. Quelle est la bonne façon de résoudre ce problème, afin que je ne reçois pas ces erreurs?

MISE À JOUR 1:

Après avoir suivi les conseils de ce fil, j’ai ajouté ces commandes avant d’exécuter "npm install":

PYTHON=/usr/sbin/python2
export PYTHON

Maintenant, je reçois cette erreur:

> node-gyp rebuild

gyp ERR! build error
gyp ERR! stack Error: not found: make
gyp ERR! stack     at F (/usr/lib/node_modules/npm/node_modules/which/which.js:40:28)
gyp ERR! stack     at E (/usr/lib/node_modules/npm/node_modules/which/which.js:43:29)
gyp ERR! stack     at /usr/lib/node_modules/npm/node_modules/which/which.js:54:16
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:99:15)
gyp ERR! System Linux 3.18.9-200.fc21.x86_64
gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /srv/visitor/node_modules/phantom/node_modules/dnode/node_modules/weak
gyp ERR! node -v v0.12.1
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok
npm WARN optional dep failed, continuing [email protected]

Je trouve absurde qu’il soit écrit "... non trouvé: fais ...". Est-il possible qu'il en soit ainsi? Si oui, comment se fait-il que les paquets s’installent correctement?

Franchement, je ne comprends rien du tout. Des idées?

8
dsljanus

Tout d’abord: je tiens à remercier tous ceux qui ont contribué à mon aide, en particulier @adarsh.

Maintenant, le vrai problème était qu'il me manquait "make" et "gcc". Au début, quand un message du compilateur l’a suggéré, j’ai trouvé cela absurde. Mais gardez à l'esprit qu'il s'agit d'une image extraite du registre Docker. 

J'ai ajouté "pacman -S --needed --noconfirm make gcc" dans mon fichier Docker, et le processus de construction est terminé avec succès.

Il va sans dire que je devais également apporter les modifications suggérées aux variables environnementales.

2
dsljanus

Essayez d'exécuter ceci

PYTHON=$PYTHON:/usr/bin/python
export PYTHON

Ajoutez ceci au fichier de profil (comme ~/.bash_profile etc. en fonction de votre shell) pour le rendre persistant.

Si votre python n'est pas installé dans /usr/bin/python, vous pouvez exécuter which python pour savoir où il est installé.

4
adarsh

Cela a fonctionné pour moi ..

node-gyp --python C:\Users\username\.windows-build-tools\python27\python.exe build

Nous devons indiquerpython.exepas seulement le dossier d’installation.

1
hacker