Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

431
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda