extrabacon / python-shell

Run Python scripts from Node.js with simple (but efficient) inter-process communication through stdio
2.11k stars 224 forks source link

How to load a script from an asar file? #176

Open chesucr opened 5 years ago

chesucr commented 5 years ago

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

Almenon commented 5 years ago

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

chesucr commented 5 years ago

@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

Almenon commented 5 years ago

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

sujiths commented 4 years ago

@chesucr Did you find a solution for this?

chesucr commented 4 years ago

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

sujiths commented 4 years ago

@chesucr Thanks. I also did that finally

johannespinger commented 4 years ago

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.