Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

432
Views
child process spawn python node js

I am trying to call a python script using node.js child process.

JS

console.log('Hello World!')

const path = require('path')
const {spawn} = require('child_process')
/**
   * Run python script, pass in `-u` to not buffer console output
   * @return {ChildProcess}
*/
function runScript(){
   return spawn('python', [
      "-u",
      path.join(__dirname, 'pythonscript.py'),
     "--foo", "some value for foo",
   ]);
}
const subprocess = runScript()


// print output of script
subprocess.stdout.on('data', (data) => {
   console.log(`data:${data}`);
});
subprocess.stderr.on('data', (data) => {
   console.log(`error:${data}`);
});
subprocess.stderr.on('close', () => {
   console.log("Closed");
});

python

mydict =    {
  "brand": "Ford",
  "model": "Mustang",
  "licensePlate" : "O XXX YYY",
  "year" : 1964,
  "insured": {
                'lastname' : 'Snow', 
                'firstname' : 'John', 
                'adress' : 'Holiday street, 4 - Paradise'
             }
}
print(mydict)

The purpose is to be able to use the dictionary created by the python code in javascript.

But a this step I am faced to an error which is provided here below.

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

Error: spawn python ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
    at onErrorNT (internal/child_process.js:470: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:274:12)
    at onErrorNT (internal/child_process.js:470:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn python',
  path: 'python',
  spawnargs: [
    '-u',
    '/mnt/c/Users/xxxx/javascript/pythonscript.py',
    '--foo',
    'some value for foo'
  ]
}

can you help me with this? I work with Ubuntu Bash for Windows 10, I don't know if this information is relevant or not...

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!