python-shell icon indicating copy to clipboard operation
python-shell copied to clipboard

How to load a script from an asar file?

Open chesucr opened this issue 6 years ago • 7 comments

Is there a way to load the script that is stored inside an asar file? I am working with electron and I need to package everything into asar file (more efficiency, signed app, etc):

var py_options = {
    mode: 'text',
    pythonPath: self.python_path,
    scriptPath: loc                 // how to write the location in the asar file here?
};
python_shell.run('get_python_version.py', py_options, function (err, results) {
    if (err) {
        console.log('>> Error running script: ' + err);
    } else {
        console.log(results[0]);
    }
});

But the file is not found if it is packaged in the asasr file. Is there a chance to make this work? Maybe using fs library somewhere? More about asar

chesucr avatar Feb 15 '19 15:02 chesucr

Take a look at my arepl electron repo, it might help you out

Almenon avatar Feb 15 '19 16:02 Almenon

@Almenon I see a python-shell dependency in your repository, but I do not see where you are using it. Could you show me please? Thanks. Should I use another different tool?

image

chesucr avatar Feb 19 '19 08:02 chesucr

Oh wait, I didn't use the script path option in my repo. I'm not sure what path you need, sorry.

Almenon avatar Feb 19 '19 16:02 Almenon

@chesucr Did you find a solution for this?

sujiths avatar Nov 15 '19 08:11 sujiths

@sujiths no, I just stored the script outside the asar file. With electron-builder you can use asar = False, or asarUnpack which is better

chesucr avatar Nov 15 '19 14:11 chesucr

@chesucr Thanks. I also did that finally

sujiths avatar Nov 16 '19 13:11 sujiths

has someone else found a working solution with having the python script inside the asar archive?

I have worked around this problem with just copying the python-script synchronously in the runtime to a path outside the asar archive and then run the script, which worked great

On Windows to copying seems to be broken, because it also loads all the files into a temp folder, but does never clean it up. So your harddisk gets full.

johannespinger avatar Feb 12 '20 13:02 johannespinger