npm - "Can't find Python executable "python", you can set the PYTHON env variable."

Pythonnode.jsNpmNpm Install

Python Problem Overview


I'm trying to run the following command: npm install -g bower gulp cordova ionic tsd@next karma-cli protractor node-gyp coffee-script js-beautify typescript npm-check

I have installed Python, Visual Studio Express and node-gyp so thought I'd be good to go, however I get the following errors:

enter image description here

Regarding the "Can't find Python executable "python", you can set the PYTHON env variable." error, I'm a little confused because I have set the PYTHON environmental variable like so:

enter image description here

Any ideas please?

Python Solutions


Solution 1 - Python

Try:

Install all the required tools and configurations using Microsoft's windows-build-tools by running npm install -g windows-build-tools from an elevated PowerShell (run as Administrator).

https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#environment-setup-and-configuration

Solution 2 - Python

Solution 3 - Python

You got to add python to your PATH variable. One thing you can do is Edit your Path variable now and add

;%PYTHON%;

Your variable PYTHON should point to the root directory of your python installation.

Solution 4 - Python

I installed python2.7 to solve this issue.

Solution 5 - Python

> Just run below command with admin access

npm install --global --production windows-build-tools

Solution 6 - Python

The easiest way is to let NPM do everything for you,

npm --add-python-to-path='true' --debug install --global windows-build-tools

Solution 7 - Python

I have recently encountered this issue in a dockerfile using node:16-alpine as base image. I have added following run command to fix the issue:

FROM node:alpine as build-stage
RUN apk add --no-cache python3 py3-pip make g++

Here, both tags node:alpine & node:16-alpine are same.

Solution 8 - Python

One of the following solutions will work for you:

  1. npm config set python c:\Python\27\python.exe or set PYTHON=D:\Python\bin\Python.exe
  2. npm config set python D:\Library\Python\Python27\python.exe
  3. Let npm configure everything for you (takes forever to complete) npm --add-python-to-path='true' --debug install --global windows-build-tools (Must be executed via "Run As Administrator" PowerShell)

If not... Try to install the required package on your own (I did so, and it was node-sass, after installing it manually, the whole npm install was successfully completed

Solution 9 - Python

You are running the Command Prompt as an admin. You have only defined PYTHON for your user. You need to define it in the bottom "System variables" section.

Also, you should only point the variable to the folder, not directly to the executable.

Solution 10 - Python

My Problem was the usage of Node v16.

I went back to Node v12 (v14 is probably fine as well) and it worked.

Solution 11 - Python

Run : npm --vs2015 install --global windows-build-tools

Solution 12 - Python

npm config set python D:\Library\Python\Python27\python.exe

This kind off worked for me from Tom Gao's answer

Make sure to change in npmrc file as it doesnt automatically takes \ for the path and do add Python in env var also as mentioned in the answers.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNickView Question on Stackoverflow
Solution 1 - Pythonkuan teinView Answer on Stackoverflow
Solution 2 - PythonTom GaoView Answer on Stackoverflow
Solution 3 - PythonjvecseiView Answer on Stackoverflow
Solution 4 - PythongusView Answer on Stackoverflow
Solution 5 - PythonLahiru AmarathungeView Answer on Stackoverflow
Solution 6 - PythonShamseer AhammedView Answer on Stackoverflow
Solution 7 - PythonTranshap HigsnView Answer on Stackoverflow
Solution 8 - PythonElharonyView Answer on Stackoverflow
Solution 9 - PythonOneCricketeerView Answer on Stackoverflow
Solution 10 - PythonPascalView Answer on Stackoverflow
Solution 11 - Pythonitas97View Answer on Stackoverflow
Solution 12 - Pythonyoyo44View Answer on Stackoverflow