0

I have a Python script that can create an excel file with information from the input given by user from the HTML UI I created with a few html pages, css and javascript. I need this to work offline and I need to distribute it to clients.

How can I bundle this HTML UI and Python file so that the client doesn't require to install Python or any dependencies to work with my app? I think eel does the job by not requiring the client to install python to work with this but in eel the client should already have chrome installed right?

Edit:

my js:

function elect() {
    console.log('Im in function right now');
    let {PythonShell} = require('python-shell');
    var path = require('path');
    var options = {
        scriptPath : path.join(__dirname, '/../engine/')
    }

var axiexe = new PythonShell ('test sort.py', options);

axiexe.on('message', function (message) {
    swal(message);
    })
}

My dir is E:\Web\testing my app\GUI inside it I have the folder node_modules with @electron, .bin, python-shelletc folders.

  • 1
    The eel documentation has a section about PyInstaller, I think that's your way to go. This tool packages Python and all necessary libraries in an .exe file (or Linux/Mac executable), so you don't need to install Python on the client machines, because the executable ships its own Python. I haven't tried it for anything UI-related, so this is just a comment and no answer. Let us know if you found a solution :) – Niklas Mertsch May 18 '20 at 12:02
  • Yea eel does install the python interpreter but it requires chrome to be installed at the first place. But in electron we dont need chrome. It already has chromium when we install but in electron it is very hard to work with this node.js modules and all. I am getting a lot of errors. I have posted it in stackflow didnt get any answer till now. –  May 18 '20 at 12:25
  • You can assume that every client has a browser installed. Do you need electron to show your HTML pages? You could have Python open the HTML pages in the browser of your client. Have you tried googling for "electron app python backend"? The results look promising to me. – Niklas Mertsch May 18 '20 at 12:31
  • a) use PyInstaller to create a onefile exe, and b) consider using PySimpleGui which is incredibly easy to use to create a simple graphical UI requiring no messing about with html/js/css - and can all be bundled up by PyInstaller to run with no other dependencies than the OS it is build on (i.e. if you run PyInstaller on Windows, the onefile exe will only run on Windows, ditto for Linux) – DisappointedByUnaccountableMod May 18 '20 at 13:01
  • @barny Is there a way that I can include a chromium browser along with eel? –  May 18 '20 at 13:04
  • PyInstaller won't bundle eel/electron/chrome. By using PySimpleGui you avoid the need for eel/electron/chrome :-) – DisappointedByUnaccountableMod May 18 '20 at 13:12

1 Answers1

0

I am working right now on the Electron app supplied with Python backend. My flow is following: 1. install Pyshell as npm module. 2. create your Electron UI 3. Compile your python code using pyinstaller.

then comes the trick. Pyshell in fact uses also a python installed on the machine. Alternative is to run a server in Python, I raised a question to myself. Why should I if I have very trivial functions?

Solution: modify python-shell to make it run exe files, also I use a trick that I say path to python is my compile python_code.exe and my script is null, then I commented lines in python-shell where check for script length occurred In communicator.js for the build version use:

let options = {
  mode: 'text',
  pythonPath: "resources/app/python_build/electron_backend.exe"
};
pyshell = new PythonShell(' ', options);

while for development Pyshell will grab your Python installation from env. variables. So we need only to provide a .py file path

pyshell = new PythonShell('electron_backend.py');

In order to make it run please change source of the pyshell module, comment following:

// if (scriptPath.trim().length == 0)
    // throw Error("scriptPath cannot be empty! You must give a script for python to run");
Beliaev Maksim
  • 968
  • 12
  • 21
  • I tried using electron. But as I am not familiar with node.js with throws me an error that I am unable to fix. I have in my javascript ```var python = require('python-shell');``` but it says that ```Module name "python-shell" has not been loaded yet for context: _. Use require([])``` what could be the reason? In the folder I have all my index.html main.js and node_module folder. In that folder I have the python-shell copied. But it still gives me the error. How to fix? –  May 18 '20 at 12:43
  • please use new package handler for node js: let {PythonShell} = require('python-shell'); – Beliaev Maksim May 18 '20 at 12:47
  • Still getting the error as ```Module name "python-shell" has not been loaded yet for context: _. Use require([])``` I will add an edit part to my question with my code. –  May 18 '20 at 12:51
  • @Derik81, can you please try to use require at the beginning of your JS code. Like import in python according to PEP – Beliaev Maksim May 18 '20 at 12:56
  • still didn't work. I need to learn more about this require thing.. –  May 18 '20 at 13:00
  • @Derik81. smth is wrong with your mainwin probably. check following ~~~var MainWindow = new BrowserWindow({ show: false, // disable show from the beginning to avoid white screen, see ready-to-show webPreferences: { nodeIntegration: true }, height: 600, width: 2*1000, resizable: false });~~~ – Beliaev Maksim May 18 '20 at 13:18
  • important is nodeIntegration here – Beliaev Maksim May 18 '20 at 13:19