felixrieseberg/windows-build-tools

Can't find Python executable "python" after installing

mikew opened this issue Β· 64 comments

mikew commented

node-gyp is failing because it can't find python. windows-build-tools did its thing and python is installed:

$ $(npm config get python)
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
$ npm --version
4.5.0
$ node --version
v7.9.0

Here's the output from node-gyp:

+ node_modules/.bin/electron-rebuild --arch x64 -f -p -w serialport -m electron-app
Γ— Rebuild Failed
An unhandled error occurred inside electron-rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@3.6.0
gyp info using node@7.9.0 | win32 | x64
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 PythonFinder.failNoPython (C:\Users\mike\Work\dronefuse-client\node_modules\node-gyp\lib\configure.js:482:19)
gyp ERR! stack     at PythonFinder.<anonymous> (C:\Users\mike\Work\dronefuse-client\node_modules\node-gyp\lib\configure.js:508:16)
gyp ERR! stack     at C:\Users\mike\Work\dronefuse-client\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:114:15)
gyp ERR! System Windows_NT 10.0.15063
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\mike\\Work\\dronefuse-client\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=1.4.13" "--arch=x64" "--dist-url=https://atom.io/download/electron" "--build-from-source" "--module_name=serialport" "--module_path=C:\\Users\\mike\\Work\\dronefuse-client\\electron-app\\node_modules\\serialport\\build\\Release" "--host=https://github.com/EmergingTechnologyAdvisors/node-serialport/releases/download/4.0.7"
gyp ERR! cwd C:\Users\mike\Work\dronefuse-client\electron-app\node_modules\serialport
gyp ERR! node -v v7.9.0
gyp ERR! node-gyp -v v3.6.0
gyp ERR! not ok
mikew commented

It's as if npm isn't even checking the value of python that is set, because this invocation works:

PATH="$(dirname $(npm config get python)):$PATH" node_modules/.bin/electron-rebuild --arch x64 -f -p -w serialport -m electron-app

Same issue here.

+1

solution: nfroidure/ttf2woff2#28
npm install --global --production windows-build-tools

Hm, seems like this is more with electron-rebuild than with npm. I assume the real solution here is to also ensure that python is globally accessible, which would require checking if it isn't already.

I'd gladly accept a PR for that, I'm not sure when I'll get to it.

https://github.com/felixrieseberg/windows-build-tools/issues/33

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

npm config set python "c:\Python\27\python.exe"

@ArminMa solution solved my issue! Had to run the CLI as administrator.

@ArminMa's solution worked for me too!

I first had Python version 3.6 for Windows installed on a Windows Server 2016 machine. I used the windows executable installation.

This was required in order to install the web3 package.

But no matter how I set path and environment variables, during the npm install of web3 it kept complaining it couldn't find the python executable. Typing python in the command prompt worked fine.

I suspect it has to do with version/compatibility issues between web3 and python. After uninstalling the 3.6 version of python and installing 2.7 using the npm command ArminMa suggested it all works!

I did update my environment variables (PYTHON and PATH) to the 2.7 executable.

Thank guys,
especially thank @ArminMa, you solved my issue.

thanks arima

thanks @aminma you save my day!

Installing python 2.* worked for me.

@garolion obrigado. Estive com esse problema por um bom tempo. Consegui corrigir com isso! πŸ₯‡

I have faced and fixed this issue relates node-sass and python error.Try installing latest angular cli command with the steps below

Set the system variable path as well:
C:\Users\windowsusername\AppData\Roaming\npm

C:\Users\windowsusername\AppData\Roaming\npm\node_modules@angular\cli\bin;

C:\Program Files\nodejs;

Then start using angular cli command prompt using:
angular client project folder path>npm install -g @angular/cli@latest

angular client project folder path>npm install -g node-gyp

Executing: npm install --global --production windows-build-tools and then
executing npm rebuild did the trick.

On windows:
Run powershell as Administrator:
and run
npm --add-python-to-path='true' --debug install --global windows-build-tools

in my case when I ran
npm --add-python-to-path='true' --debug install --global windows-build-tools
or
npm install --global --production windows-build-tools
it hags forever at this
---------- Visual Studio Build Tools ----------
Still waiting for installer log file...
---------- Visual Studio Build Tools ----------
Still waiting for installer log file...
------------------- Python --------------------

---------- Visual Studio Build Tools ----------
Successfully installed Visual Studio Build Tools
------------------- Python --------------------
=== Logging stopped: 8/17/2018 10:22:57 ===

Thank you all, we're quite confident that most of these issues are now fixed πŸ™‡

Still getting this :

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 PythonFinder.failNoPython (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:483:19)
gyp ERR! stack     at PythonFinder.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:508:16)
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:152:21)
gyp ERR! System Windows_NT 10.0.15063
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd c:\Users\Julien.MARANTES\Documents\workspace\enfrasys\nbdtm-back\node_modules\unix-dgram
gyp ERR! node -v v8.11.4
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok

@yume117 you must close all CMD windows after installing windows-build-tools to refresh PATH env variable

I see python in my PATH variable as well as set up python as a environment variable. Tried everthing from above. It keeps failing with the same error. Not sure, how to fix it. Any help would be deeply appreciated

C:\Users\krish\Projects\ethereum\helloworldreact\client>echo %python%
C:\Users\krish.windows-build-tools\python27

C:\Users\krish\Projects\ethereum\helloworldreact\client>echo %PATH%
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files\nodejs;C:\Program Files\PuTTY;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Go\bin;**C:\Users\krish.windows-build-tools\python27;**C:\Users\krish\AppData\Local\Microsoft\WindowsApps;C:\Users\krish\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\krish\AppData\Roaming\npm;C:\Users\krish\AppData\Local\atom\bin;C:\Users\krish\AppData\Local\Microsoft\WindowsApps;C:\Users\krish\go\bin

C:\Users\krish\Projects\ethereum\helloworldreact\client\node_modules\keccak>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "C:\Users\krish.windows-build-tools\python27", you can set the PYTHON env variable.
gyp ERR! stack at PythonFinder.failNoPython (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:484:19)
gyp ERR! stack at PythonFinder. (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:509:16)
gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:154:21)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\krish\Projects\ethereum\helloworldreact\client\node_modules\keccak
gyp ERR! node -v v10.11.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! keccak@1.4.0 rebuild: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the keccak@1.4.0 rebuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\krish\AppData\Roaming\npm-cache_logs\2018-09-23T22_03_47_165Z-debug.log
"Keccak bindings compilation fail. Pure JS implementation will be used."

What is your NPM and Node versions? (node --version and npm --version) Please update your Node version to latest LTS. Did you installed windows-build-tools from CMD with admin access? Installing windows-build-tools took some time. You must wait until installation is really finished

npm - 6.4.1
node - 10.11.0

I finally got it working with a very simple change. I re-installed Python for "All Users" insted of option "Only for me".

Updated Path variables for "python" & "path". Compilation worked well
Note: "truffle compile" does not work from "command prompt". But works well in "Powershell".

This was a minute work in LINUX & Mac, but a couple of days effort in Windows. When will Microsoft make Windows developer friendly????

npm install --global --production windows-build-tools
Later installed this, you must specified the python2.7 link.

For that, you must search in your computer but must be locate in something like this:

C:\Users\USERNAME.windows-build-tools\python27\python.exe

So just execute this in your bash:

npm config set python "C:\Users\USERNAME.windows-build-tools\python27\python.exe"

Need to fix hands.

PS G:\nodejs\test> node-gyp configure
gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@8.12.0 | win32 | x64
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 PythonFinder.failNoPython (C:\Users\Alex\AppData\Roaming\npm\node_modules\node-gyp\lib\configure.js:484:19)
gyp ERR! stack     at PythonFinder.<anonymous> (C:\Users\Alex\AppData\Roaming\npm\node_modules\node-gyp\lib\configure.js:509:16)
gyp ERR! stack     at C:\Users\Alex\AppData\Roaming\npm\node_modules\node-gyp\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:152:21)
gyp ERR! System Windows_NT 10.0.16299
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Alex\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure"
gyp ERR! cwd G:\btc-test\rpc-miner
gyp ERR! node -v v8.12.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

We're interested in that file. Change to your windows user name
C:\Users\Alex\AppData\Roaming\npm\node_modules\node-gyp\lib\configure.js
line number 32
var python = gyp.opts.python || process.env.PYTHON || 'python2'
change to your python location
var python = 'C:\\Python\\27\\python.exe'

function configure (gyp, argv, callback) {

  //var python = gyp.opts.python || process.env.PYTHON || 'python2'
  var python = 'C:\\Python\\27\\python.exe'
    , buildDir = path.resolve('build')
    , configNames = [ 'config.gypi', 'common.gypi' ]
    , configs = []
    , nodeDir
    , release = processRelease(argv, gyp, process.version, process.release)

Hi All,
I am trying to call a C++ module from Node.js by using the ADDONS. The node-gyp configure is getting failed with the following Error. I am surpise why it searches for Python? I am not using Python at all.
C:\Ram\Projects\GraphQL\t\addon>node-gyp configure
gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@10.13.0 | win32 | x64
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Software\Python37-32\python.exe -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack File "", line 1
gyp ERR! stack import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack at ChildProcess.exithandler (child_process.js:289:12)
gyp ERR! stack at ChildProcess.emit (events.js:182:13)
gyp ERR! stack at maybeClose (internal/child_process.js:962:16)
gyp ERR! stack at Socket.stream.socket.on (internal/child_process.js:381:11)
gyp ERR! stack at Socket.emit (events.js:182:13)
gyp ERR! stack at Pipe._handle.close (net.js:606:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "C:\software\nodejs\node.exe" "C:\Users\Admin\AppData\Roaming\npm\node_modules\node-gyp\bin\node-gyp.js" "configure"
gyp ERR! cwd C:\Ram\Projects\GraphQL\t\addon
gyp ERR! node -v v10.13.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

C:\Ram\Projects\GraphQL\t\addon>
capture

I also have attached the error.

Appreciate if any one can help.

Hello @ramprasad2018, what you are seeing is a bug in node-gyp where it fails to notify you that it can only work with python2.
You can work around this until the fix is published, by running with:
node-gyp --python /path/to/python2.7
or setting:
npm config set python /path/to/executable/python2.7
Ref: https://github.com/nodejs/node-gyp#option-2

solution: nfroidure/ttf2woff2#28
npm install --global --production windows-build-tools

In my case npm wasn't finding the python.exe file when trying to run npm rebuild node-sass. After running "npm install --global --production windows-build-tools", I was able to run the command.
Thanks @ArminMa

"Error: not found: C:\Users\username\.windows-build-tools\python27\python.exe"

https://github.com/felixrieseberg/windows-build-tools/issues/33

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

@ArminMa Thanks

1 - Just uninstall Python from "C:\Users\username\.windows-build-tools\python27"
2 - Reinstall running the msi install file, not command line. Link: https://www.python.org/downloads/release/python-2715/
2.1 - Check the option "Install for all users" and install on "C:\python27".

Now node-gyp will find the Python normally

i encountered the same issue as @ramprasad2018 and with @refack and @maikonmatheus comments I was able to get it working by uninstalling Python 3.7 and then reinstalling/repairing Python 2.7 (which apparently came with my python 3.7 download) and then running npm install again

I finally got it working with a very simple change. I re-installed Python for "All Users" insted of option "Only for me".

Updated Path variables for "python" & "path". Compilation worked well
Note: "truffle compile" does not work from "command prompt". But works well in "Powershell".

This was a minute work in LINUX & Mac, but a couple of days effort in Windows. When will Microsoft make Windows developer friendly????

As mentioned by @KrishnanSriram I was able tosolve this by running npm rebuild in "PowerShell" as administrator, it does not work on command prompt for me.

δΈΊδ»€δΉˆ Python ε˜ι‡ι…θΏ‡δΊ† 还是ζŠ₯can't find Python executable "python 2.7"? You can set the PYTHON env variable

@iamveritas How did you fix it?

image

I've set npm config python path to point to 2.7 after running

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

Here's config list after setting up python 2.7

image

lukos commented

The problem is more fundamental than is mentioned here. A node module should not have a hard dependency on a build system like Python or MSBuild unless it can download one and install it without privileges locally or hold the user's hand.

This package is a help but it doesn't solve the problem because if, for example, you need to install it from an admin account, it gets installed in the admin account which makes it unusable for the non-admin users.

I had to delete where it was installed and then manually install the Python executable for all users, but the modify path didn't seem to do anything because it still didn't work. I then manually added the PYTHON environment variable before it would work.

Thanks for this package but it should either have some more instructions, a better default example in the docs (and shouldn't be needed if people didn't make ridiculous node package like node_gyp)!

https://github.com/felixrieseberg/windows-build-tools/issues/33

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

Thank you so much @ArminMa!

Special thanks goes to @ArminMa ! works for me!

1 - Just uninstall Python from "C:\Users\username.windows-build-tools\python27"
2 - Reinstall running the msi install file, not command line. Link: https://www.python.org/downloads/release/python-2715/
2.1 - Check the option "Install for all users" and install on "C:\python27".

Now node-gyp will find the Python normally

it works halfway for me after I install python I need to install visual studio_BuildTools manually and select few other package too . now its working fine

solution: nfroidure/ttf2woff2#28
npm install --global --production windows-build-tools

it worked <3

npm config set python "c:\Python\27\python.exe"

@jeanru, this command destroyed my development machine.

To fix this, remove npm env variables from ~/.npmrc

If you ever come across the above error on windows:
Run CMD as Administrator:
and run.
npm --add-python-to-path='true' --debug install --global windows-build-tools

that's all...

B4Lee commented

I just solved the problem by reading this article

https://spin.atomicobject.com/2019/03/27/node-gyp-windows/

hope it helps !!

Thanks Satish.

Configuration: window 10, 64 bit, node v8.13.0, npm v6.4.1

Follow the below steps :

  1. Restart the system

  2. Open cmd by administrator

  3. Delete C:\Users\user_name.node-gyp

  4. Delete %AppData%/npm

  5. Delete %AppData%/npm-cache

  6. Check out node-gyp package

  7. npm install -g node-gyp

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

  9. node-gyp configure --python C:\Users\pcq158.windows-build-tools\python27\python.exe

  10. npm config set msvs_version 2017 --global

  11. npm install

I had to re-install python 2.7 and change npm python config to:

npm config set python "c:\Python27\python.exe"

For Ubuntu 18.04.4 LTS
npm --add-python-to-path='true' --debug install --global build-tools

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

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! windows-build-tools@5.2.2 postinstall: `node ./dist/index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the windows-build-tools@5.2.2 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\lserrano\AppData\Roaming\npm-cache\_logs\2020-09-15T18_29_25_510Z-debug.log

Still having the issue

Its not working on Ubuntu:

npm --add-python-to-path='true' --debug install --global windows-build-tools
npm ERR! code EBADPLATFORM
npm ERR! notsup Unsupported platform for windows-build-tools@5.2.2: wanted {"os":"win32","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! notsup Valid OS:    win32
npm ERR! notsup Valid Arch:  any
npm ERR! notsup Actual OS:   linux
npm ERR! notsup Actual Arch: x64

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/adam/.npm/_logs/2020-12-04T14_01_39_361Z-debug.log

Any ideas how to fix it on Linux?

@jacobq whoups. Just realized that I was actually missing Python at all.lol..

https://github.com/felixrieseberg/windows-build-tools/issues/33

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

i think i love you. it worked man, thanks a lot!

Its not working on Ubuntu:

npm --add-python-to-path='true' --debug install --global windows-build-tools
npm ERR! code EBADPLATFORM
npm ERR! notsup Unsupported platform for windows-build-tools@5.2.2: wanted {"os":"win32","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! notsup Valid OS:    win32
npm ERR! notsup Valid Arch:  any
npm ERR! notsup Actual OS:   linux
npm ERR! notsup Actual Arch: x64

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/adam/.npm/_logs/2020-12-04T14_01_39_361Z-debug.log

Any ideas how to fix it on Linux?

How did you fix it? i have the same problem on macos

Its not working on Ubuntu: ...

How did you fix it? i have the same problem on macos

As the name windows-build-tools is intended to suggest, this package is for installing Windows software needed to build native extensions/modules for NodeJS. It is completely unnecessary on Linux and MacOS. If you are intending to "cross-compile" Windows things on a non-Windows platform then I recommend using a virtualization layer (e.g. VirtualBox, Parallels, etc.) or cloud CI/CD offering (e.g. AppVeyor).

run: npm cache clean --force
delete node_modules
delete packagelock.json and yarn.lock(if have)
run: npm install

Installing Python from the official source fixed this issue on Windows after restarting the machine...

solution: nfroidure/ttf2woff2#28
npm install --global --production windows-build-tools

Thanks !!

OxQ commented

Installing python (for Windows) using Microsoft Store has helped me.

after install windows build tools type
npm config set msvs_version 2017
saved me