143

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?

7
  • 1
    Is there an underscore in your actual path? Commented Dec 19, 2015 at 16:03
  • Thanks @PadraicCunningham, yes there is i.imgur.com/1kuv8Pw.png Commented Dec 19, 2015 at 16:05
  • 1
    Can you post the full evn exactly as you have it set? You can also add it to your PATH Commented Dec 19, 2015 at 16:06
  • 1
    Set it to your folder with the executable, C:\Program Files\Python_2.7.10 or add to your PATH stackoverflow.com/a/4855685/2141635 under system variables Commented Dec 19, 2015 at 16:08
  • 1
    no prob, you're welcome. You can add and accept an answer that worked for you Commented Dec 19, 2015 at 16:19

20 Answers 20

132

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

Sign up to request clarification or add additional context in comments.

9 Comments

This did the trick on my behalf. Pretty annoying though that it will install Python 2.7 as I don't want to soil my environment with a Python version that I'm not going to use.
It should be the perfect answer.
Fixed this error, and probably others I haven't hit yet. Going into the list of dev machine setup steps!
is system restart required after that? it appears yes for me to get work
the command currently returns this response "[email protected]: Node.js now includes build tools for Windows. You probably no longer need this tool. See github.com/felixrieseberg/windows-build-tools for details."
|
49

https://github.com/nodejs/node-gyp#on-windows

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

try

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

2 Comments

This resulted in npm ERR! python is not a valid npm option
the 'python' option was removed with npm v9 - see stackoverflow.com/questions/74522956/….
42

I installed python2.7 to solve this issue.

7 Comments

This fixed my issue...sadly.
@ZhangBuzz It's because the gyp tool that node-gyp depends on was written for Python 2 and is not compatible with Python 3.
2021 here, they still want it aaand the 2.7 cannot be installed due to bug (endless cycle).
and now 2022 here!
@LachoTomov get out of the waterfall cycle its agile world, patches and version upgrades are required for fixing bugs and exploits or loose your bitcoin wallets to hippies
|
35

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.

6 Comments

Thank you, I've set the PYTHON path to C:\Program Files\Python_2.7.10;%PYTHON%; but I'm still getting the same error unfortunately
Actually you want to set your python path to C:\Program Files\Python_2.7.10 and then edit your PATH Variable and add ;%PYTHON; . I've looked it up locally and i added C:\Python34;C:\Python34\Scripts; to get things working. Although as you see im not using Python 2.
Actually this post: stackoverflow.com/a/21433154/3378288 describes exactly what i was trying to explain but in a more detailed way ;). For you to note: it's not important if your path variable is PY_HOME, or PYTHON. It's just important that it matches with what you insert in your path variable.
omg... I didn't realise I had to close the command window for the new variables to be in play. Thank you all so much for the replies and advice!
Installing Python2.7.10 and setting the PATH and PYTHON environment variables successfully resolved the issue. Thanks you @jvecsei
|
29

Just run below command with admin access

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

2 Comments

The package windows-build0tools is deprecated: npmjs.com/package/windows-build-tools
It shows me "Downloading installers failed. Error: TypeError: 'process.env' only accepts a configurable, writable, and enumerable data descriptor" using npm v9.6.7 with Node.js v18.17.1
12

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

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

1 Comment

Don't think this is merged in yet, and it didn't work on this end - github.com/nodejs/node-gyp/pull/1109
12

MAC: In my case, I just run the below command and the error resolved:

npm config set python python3

2 Comments

This one introduce more errors like ` Missing parentheses in call to 'print'. Did you mean print`
npm ERR! python` is not a valid npm option`
10

My Problem was the usage of Node v16.

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

1 Comment

Any idea why this fixes it? Does it not use python?
9

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.

1 Comment

add RUN apk add --no-cache python3 py3-pip make g++ to docker file solved my issue, thnx!
6

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

1 Comment

First installing node-sass manually actually worked for me. Had been struggling with python thing.
4

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.

3 Comments

Thank you, I've added C:\Program Files\Python_2.7.10;%PYTHON%; in as the PYTHON variable under System variables and unfortunately am still getting the same error :(
As mentioned in the other comments, %PYTHON% should go in the PATH variable, not PYTHON. By adding it in PYTHON, you are making a circular reference, which is not good for your computer.
Thank you, have just changed PYTHON and included it in the PATH variable and still getting the same error. Argh :(
4

Had this issue on node:18 alpine docker image on Apple Silicon where only python3 is available but at least some versions of node-gyp don't support pyhton3 yet. So I had to use an alpine version that still had python2:

FROM node:18.8.0-alpine3.15

WORKDIR /app

RUN apk --no-cache add python2 make g++

COPY package.json .
COPY yarn.lock .
RUN yarn

COPY . .

Comments

2

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

1 Comment

perfect answer since this fixes the missing python2.7 issue too
2
delete node_modules 
delete packagelock.json and yarn.lock(if have)
npm cache clean --force
npm install

Comments

1
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.

Comments

0

as mentionned by jvecsei

For me adding D:\Softwares\Python\2.7\Scripts instead of D:\Softwares\Python\2.7 to PATH worked.

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
0

npm config set python $(which python)

Comments

0

On macOS installing Python 2 solves this:

With asdf, in a .tool-versions file:

python 2.7.18

Then

asdf plugin add python
asdf install

Comments

-1

use node version which mentioned in package.json.

using nvm (node version manager) you can switch between respective node version mentions in package.json

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
-1

For ubuntu:

sudo apt-get update
sudo apt install python2

Check python 2 version:

python2 --version

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.