0

I was trying to figure out an issue wherein I'm unable to commit changes via Github Desktop due to a failure in executing a pre-commit hook. It turns out that a nodejs script to format the code is run which invokes a Python command internally. This script fails while spawning the Python process. Here's some minimal code I used to replicate my issue:

const { spawn } = require('child_process');
console.log(process.env.PATH);
const py = spawn('python', ['-V']);

This first prints the path which matches what I obtain from echo %PATH% but then fails with

events.js:291
      throw er; // Unhandled 'error' event
      ^

Error: spawn python ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn python',
  path: 'python',
  spawnargs: [ '-V' ]

I've looked at answers like this but the steps didn't seem to work for me since everything appears to be in place as per the suggestions in the answer. I believe my situation might be different since I don't have a system python installed on the Win machine but use python via pyenv-win.

where python yields

C:\Users\me\.pyenv\pyenv-win\shims\python
C:\Users\me\.pyenv\pyenv-win\shims\python.bat

The env.PATH printed by the script too has these paths.

file C:\Users\me\.pyenv\pyenv-win\shims\python yields

C:\Users\me\.pyenv\pyenv-win\shims\python: POSIX shell script, ASCII text executable, with CRLF line terminators

and yes, python -V prints Python 3.9.4 and merely typing python gets me to the Python interpreter.

OS: Win 10

Shell: Cmder (I'm able to drop into the Python interpreter even on CMD shell though where I run into the same issue)

What else should I try to get this working?

EDIT: I suspect that the issue is because of no Python executable in the path because when I activate a virtual environment, this is the output of where python

C:\Users\me\torq-native\venv\Scripts\python.exe
C:\Users\me\.pyenv\pyenv-win\shims\python
C:\Users\me\.pyenv\pyenv-win\shims\python.bat

where C:\Users\me\torq-native\venv\Scripts\python.exe is the actual python executable. Even though the script at C:\Users\me\.pyenv\pyenv-win\shims\python is set to be executable, for some reason that doesn't qualify it seems.

Zoso
  • 2,958
  • 1
  • 14
  • 25

0 Answers0