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

373
Vistas
How do I run a Python script within a JavaScript file

I am using React.JS to create a website, and I have a button that the user can press that will trigger some python file to be run. I've tried using child_process, but I get a ton of errors that I can't seem to find the answer to. Can anyone tell me where I'm going wrong?

This is my code so far:

import React from 'react'
import '../css/Home.css'


const Home = () => {

    const runPyFile = () => {
        const spawn = require('child_process');
    
        const childPython = spawn('python', ['../python/test.py']);
    
        childPython.stdout.on('data', (data) => {
            console.log(`stdout: ${data}`);
        });
    
        childPython.stderr.on('data', (data) => {
            console.log(`stderr: ${data}`);
        });
    
        childPython.on('close', (code) => {
            console.log(`child process exited with code ${code}`);
        });
    };
    

    return (

        <body className='home-body'>
        
            {/* a button that will run the python script */}
            <button onClick={runPyFile}>
                Run Python Script
            </button>

        </body>
        
    )
}

export default Home

And here is the python file I am trying to run:

print('hello world!')

When I run all of this, and click this button in the browser, I receive this error: enter image description here

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

What you are trying to do is run a python script from within javascript running in the browser on the client side inside a separate process. I'm afraid you cannot do this because it's a security issue to try to break out of the browser sandbox and reach into the user's computer. Browsers don't allow that. You can't even open a file in the user's space outside the browser.

You are perhaps confused by the idea that if you are writing server side code, you can do things like this there, but that's only available on the server side.

All that said, there are ways to run python code in the browser. Have a look at brython and pyodide

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can't do that in client side.

about 4 years ago · Juan Pablo Isaza Denunciar
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