Skip to content

gyp can't find Python, despite Python running when you type "python" #1268

Closed

Description

@Pomax

I'm trying to install windows-registry on Windows 10 with Node 8.2.1 and NPM 5.3.0, and when the ref dependency is hit, node-gyp kicks in. However, it seems to fail when it tries to run python, despite the fact that python has a PATH entry and will run perfectly fine both when just executing "python" on the command line, or when exec/spawning a command called "python".

The error log is as follows:

c:\Users\Mike\Documents\git\temp\pluginboutique>npm install windows-registry

> ref@1.3.4 install c:\Users\Mike\Documents\git\temp\pluginboutique\node_modules\ref
> node-gyp rebuild


c:\Users\Mike\Documents\git\temp\pluginboutique\node_modules\ref>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "C:\Program Files\Python35\python.EXE", 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\Mike\Documents\git\temp\pluginboutique\node_modules\ref
gyp ERR! node -v v8.2.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ref@1.3.4 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ref@1.3.4 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I don't understand why there would be any reason to be looking for Python in the indicated locations when there is already a PATH binding that makes python run just fine:

c:\Users\Mike\Documents\git\temp\pluginboutique>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

But even then, that is the correct location as is evidenced by:

c:\Users\Mike\Documents\git\temp\pluginboutique>"C:\Program Files\Python35\python.EXE"
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

And even node will happily run "python" through exec/spawn:

c:\Users\Mike\Documents\git\temp\pluginboutique>node
> var spawn = require('child_process').spawn;
undefined
> var willError = spawn('obviousnonexistentcommand');
undefined
> Error: spawn obviousnonexistentcommand ENOENT
    at exports._errnoException (util.js:1024:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
    at onErrorNT (internal/child_process.js:374:16)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)
> var python = spawn('python');
undefined
>

Activity

  1. bnoordhuis commented on Aug 19, 2017

    @bnoordhuis
    Member

    node-gyp (or rather, gyp) needs python 2.7, python 3.x won't work.

  2. Pomax commented on Aug 19, 2017

    @Pomax
    Author

    That sounds... weird, in 2017? It's been many, many years by now for codebases to update to something that will run just fine on modern python.

    But, if you're right: the error does not in any way mention this, so if that's really the problem the error message needs to be changed here so that users understand what's wrong and can address that.

    (I don't use python except for my work, and all that work involves Python 3. so as a JS developer I have no reason to install an older version of Python unless something tells me it needs it)

  3. refack commented on Aug 20, 2017

    @refack
    Contributor

    (I don't use python except for my work, and all that work involves Python 3. so as a JS developer I have no reason to install an older version of Python unless something tells me it needs it)

    @pomex, I do agree that the error should be more informative. So I opened #1269

    Just for general context, for several reasons (which we try very hard to avoid in node) one of which is that python3 is not backwards compatible, python2 and python3 are two separate but equal branches living in parallel.

  4. vamsi248 commented on Jan 9, 2018

    @vamsi248

    @Pomax same error i am getting how to fix this issue.. did you fixed this issue in your case??

  5. lalomartins commented on Jan 22, 2018

    @lalomartins

    In case anyone else lands here looking for the solution to this and wants to subscribe to the Python 3 support issue, it's #1337

  6. SatishMHiremath commented on Feb 17, 2018

    @SatishMHiremath

    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 @latest

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

  7. LaysDragon commented on Mar 31, 2018

    @LaysDragon

    It looks like the PythonFinder is broken for some reason. It just pop up an error that say it can't find the executable at "C:\Program_Files\Python\Python36\python.exe". This is wired,hah. The executable just here and it just can't find it??? After a little debug,I found it just go into the guessPython function and trying to find the "C:\python27\python.exe" and show with a "C:\Program_Files\Python\Python36\python.exe" misleading error message.

  8. JonnyWideFoot commented on Jun 19, 2018

    @JonnyWideFoot

    Installing Python 2.7.15 fixed this for me...

  9. golyalpha commented on Jul 11, 2018

    @golyalpha

    It's 2018, and this is still an issue.

    This issue is becoming even bigger as Python2 is being phased out (It can't even be downloaded from the front page anymore, you have to go through "other downloads" on python.org), this is something that needs fixing.

  10. Bertware commented on Jul 12, 2018

    @Bertware

    There's a PR for this, but the maintainers don't seem to care: #1335

  11. thorizer commented on Jul 26, 2018

    @thorizer

    any news ?

  12. ivanjx commented on Jul 27, 2018

    @ivanjx

    THIS IS SO IRRITATING....

  13. imimdou commented on Jul 28, 2018

    @imimdou

    I had the same issue but I resolved it by adding the system variables paths like @SatishMHiremath explained above and then moved these paths to the top of the list (very important)

    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;

    Make sure these paths are at the top of the list instead of the default bottom
    Restart cmd and good to go

  14. golyalpha commented on Jul 28, 2018

    @golyalpha

    @imimdou A workaround for now, but doesn't change the fact that gyp is using outdated python to run, not to mention that this is not an error that affects just angular - it's much more generic in nature.

  15. pauldraper commented on Sep 12, 2018

    @pauldraper

    separate but equal

    2 < 3

  16. lalomartins commented on Sep 12, 2018

    @lalomartins

    The “separate but equal” thing is outdated anyway, it was true when written but as @golyalpha mentions later py2 is now being phased out and no longer supported.

  17. prakis commented on Nov 19, 2018

    @prakis

    If someone wondering where that python path is stored
    its in npm config which is ".npmrc"
    you can get the config values by "npm config list" or get individual values by "npm config get" set it with "npm config set"

    https://docs.npmjs.com/cli/config

  18. jalle007 commented on Feb 18, 2019

    @jalle007

    node-gyp (or rather, gyp) needs python 2.7, python 3.x won't work.

    this is exact reason why I HATE so much that so called Open-Lunatic-Broken-Source-Community

  19. addaleax commented on Feb 18, 2019

    @addaleax
    Member

    @jalle007 I know that it can be frustrating to wait for an issue to be resolved, but this is being worked on and comments that only voice such frustration are not helpful.

  20. golyalpha commented on Feb 21, 2019

    @golyalpha

    @addaleax that is to be expected though, innit? Look at the issue opening date! Not to mention, the issue got closed without a proper fix...

  21. pauldraper commented on Mar 2, 2019

    @pauldraper

    python2 and python3 are two separate but equal branches living in parallel.

    At least for the next 9 months, 30 days, 2 hours, and 16 minutes.

    https://pythonclock.org/

  22. ORESoftware commented on Mar 2, 2019

    @ORESoftware
    Contributor

    i think i fixed this by installing

    python as python v2
    python2 as python v2
    python3 as python v3

  23. golyalpha commented on Mar 2, 2019

    @golyalpha

    @ORESoftware Yes, that is a workaround, currently, but we're getting closer and closer to Python 2 being EOL, so gyp desperately needs to be updated.

  24. Earl-Brown commented on Mar 27, 2019

    @Earl-Brown

    This worked for me:

    npm config delete python

  25. spaceneenja commented on Nov 2, 2019

    @spaceneenja

    For those coming to this thread still, I fixed this issue. I'm not sure which combination of these steps worked, but the final 2 steps are critical.

    choco install python2
    delete node_modules
    delete npm-cache
    delete package-lock.json
    npm install

  26. rahuljograna commented on Sep 2, 2021

    @rahuljograna

    open Powershell with administrator privileges and run this command, then proceed with bcrypt installation

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

  27. cclauss commented on Sep 2, 2021

    @cclauss
    Contributor

    windows-build-tools will install Python 2 which died on 1/1/2020 (600+ days ago) and which is no longer supported by current versions of node-gyp.

  28. locked as resolved and limited conversation to collaborators on Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions