Im new to Javascript so I would like to keep it at the bare minimum. Is there a way that I can use the Electron to communicate with python script without having node.js? My app is just a basic app that takes some input from users from a html page and I need this text input to be processed in python and write an excel file. So there is not much happening in html so is there a simple way to transfer the input to python file? I want to use Electron because I need this html to be my UI and also I need to distribute this app.
-
does "without having node.js" mean, without having it installed on your machine? Electron comes with its own node, so Node will always be running when you run an electron app, but you don't need it installed on your machine to run the app. however, you will need it on your machine to develop electron apps – pushkin May 18 '20 at 14:45
-
if I write a backend in python. Will the user require python installed to work that? I mean does the electron installer act like PyInstaller where the user wont require python to execute the file – May 18 '20 at 15:53
2 Answers
I guess the answer is "no": the main process running node will always be there.
An Electron app consists of a JavaScript main process, and one or more JavaScript renderer processes. There is no built-in Python support. And the user will need Python already installed. So, it sounds like a poor fit for what you need.
The answers here may be useful, and will show how to call the python script. I took a quick look at the flexx toolkit mentioned there. It seems to work with the user's browser, rather than producing a single executable.

- 27,837
- 13
- 117
- 217
Recently i have done it with some sort of trick hope it will help you and there are the following step which i followed-
- Created a stand alone python exe using pyinstaller and the exe has flask server internally then i put the flask server inside my node application.
Now we have to initiate our flask server and send a request to it for processing, i have done this with the help of "execFile" function as a child process, for which i have created a function and the code was something like that-
async function callFlask(){ var child = require('child_process').execFile; child('path_to_python_exe ', function(err, data) { if(err){ console.error(err); return; } }); }
Now we have initiated our flask server then will send the request with the help of fetch request like
await callFlask().then( await fetch('host_ip_defined_in_flask'+encodeURIComponent('data'))
- Now further we can extend our then chain to get response from python if any and proceed further forexample -
await callFlask().then( await fetch('host_ip_defined_in_flask'+encodeURIComponent('data')) .then(res => res.text()) .then(body => console.log(body)))
Here, your output data which python return will be printed in console then you can make your node application behave differently depending on output returned by it.
- Also you can package your app with available packagers for electron like electron-packager it will work like a charm.
Also there is are some disadvantage for using python as like it will increase your package size and the process will be difficult to kill from electron after processing so it will increase burden on host machine.
I am assuming that Explaining to create a flask server is not the scope of this question instead if you face any issues let me know, i hope it will help...

- 43
- 6
-
Actually, I dropped Electron and took Eel. Eel is simple and perfect for my use. Thanks anyway – May 29 '20 at 14:08