npm – "Can't find Python executable "python", you can set the PYTHON env variable."
Question:
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:
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:
Any ideas please?
Answers:
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.
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.
https://github.com/nodejs/node-gyp#on-windows
try
npm config set python D:LibraryPythonPython27python.exe
I installed python2.7 to solve this issue.
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).
The easiest way is to let NPM do everything for you,
npm --add-python-to-path='true' --debug install --global windows-build-tools
One of the following solutions will work for you:
- npm config set python
c:Python27python.exe
or set PYTHON=D:PythonbinPython.exe
npm config set python D:LibraryPythonPython27python.exe
- 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
Just run below command with admin access
npm install --global --production windows-build-tools
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.
My Problem was the usage of Node v16.
I went back to Node v12 (v14 is probably fine as well) and it worked.
Run : npm –vs2015 install –global windows-build-tools
npm config set python D:LibraryPythonPython27python.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.
use node version which mentioned in package.json.
using nvm (node version manager) you can switch between respective node version mentions in package.json
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 . .
delete node_modules
delete packagelock.json and yarn.lock(if have)
npm cache clean --force
npm install
as mentionned by jvecsei
For me adding D:SoftwaresPython2.7Scripts instead of D:SoftwaresPython2.7 to PATH worked.
MAC: In my case, I just run the below command and the error resolved:
npm config set python python3
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:
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:
Any ideas please?
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.
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.
https://github.com/nodejs/node-gyp#on-windows
try
npm config set python D:LibraryPythonPython27python.exe
I installed python2.7 to solve this issue.
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).
The easiest way is to let NPM do everything for you,
npm --add-python-to-path='true' --debug install --global windows-build-tools
One of the following solutions will work for you:
- npm config set python
c:Python27python.exe
orset PYTHON=D:PythonbinPython.exe
npm config set python D:LibraryPythonPython27python.exe
- 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
Just run below command with admin access
npm install --global --production windows-build-tools
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.
My Problem was the usage of Node v16.
I went back to Node v12 (v14 is probably fine as well) and it worked.
Run : npm –vs2015 install –global windows-build-tools
npm config set python D:LibraryPythonPython27python.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.
use node version which mentioned in package.json.
using nvm (node version manager) you can switch between respective node version mentions in package.json
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 . .
delete node_modules
delete packagelock.json and yarn.lock(if have)
npm cache clean --force
npm install
as mentionned by jvecsei
For me adding D:SoftwaresPython2.7Scripts instead of D:SoftwaresPython2.7 to PATH worked.
MAC: In my case, I just run the below command and the error resolved:
npm config set python python3