0

This is my PythonSHELL script in my electron.js :

const {PythonShell} = require('python-shell');
    const path = require('path');
    const options = {
        mode: 'text',
        pythonPath: 'C:/Users/abdou/AppData/Local/Programs/Python/Python38/python.exe',

        scriptPath: isDev ?  `${path.join(__dirname, "db")}`: `${path.join(__dirname, "../../build/db")}`,
    };
    mainWindow.webContents.on('did-finish-load', ()=>{
    PythonShell.run('p.py', options, function (err, results) {
        if (err) throw err;
        // results is an array consisting of messages collected during execution
         mainWindow.webContents.send('data', results[0]);
        })

    });

and this is my package.json scripts tag :

 "react-start": "react-scripts start",
"react-build": "react-scripts build",
"react-test": "react-scripts test --env=jsdom",
"react-eject": "react-scripts eject",
"electron-build": "electron-builder",
"release": "yarn react-build && electron-builder --publish=always",
"build": "yarn react-build && yarn electron-build",
"start": "concurrently \"cross-env BROWSER=none yarn react-start\" \"wait-on http://localhost:3000 && electron .\""

and this the build tag :

 "build": {
"appId": "com.gs_client_descktop",
"asar": false,
"extraResources": [
  "**/db/**/*"
]}

the message error is :

Uncaught Exeption:
    spawn C:/Users/abdou/AppData/Local/Programs/Python/Python38/python.exe ENONENT
    at Process.ChildProcess._handle.onexit(intrnal/child_process.js:264:19)
    at onErrorNT (internal/child_process.js:456:16)
    at processTicksAndRejections(internal/process/task_queues.js:77:11)

Thanks.

YAGOUBI A.E.K
  • 101
  • 1
  • 4
  • This means that the `python.exe` in the given path doesn't exist, see [this answer](https://stackoverflow.com/questions/43260643#43260706). Are you sure that you have Python installed on both machines? – Alexander Leithner Feb 23 '20 at 14:23
  • I don't want to install python in both machine I want just install my application – YAGOUBI A.E.K Feb 23 '20 at 14:28
  • Well, then this won't work, since `python-shell` will actually try to spawn a Python process. As seen in your error message, this fails because Python is not installed on the second computer. – Alexander Leithner Feb 23 '20 at 17:58
  • can you give me a solution that I can use python in electron app without installing python in all computer? – YAGOUBI A.E.K Feb 23 '20 at 18:43
  • You can't, AFAIK. Using Python requires a Python interpreter which needs to be implemented one way or another, so it's really the best idea to ship your app with a Python package/installer. – Alexander Leithner Feb 27 '20 at 16:39

1 Answers1

0

The answer is very clear. You have linked the pythonPath to the interpreter on your computer. The path you have given over there ( In this case --> pythonPath: 'C:/Users/abdou/AppData/Local/Programs/Python/Python38/python.exe') only exists on your computer. So it shouldn't work.

As a solution you could use a python virtual environment in the project. Then link the interpreter which is there in the virtual environment to the Python path. Most probably the path set to the virtual environment will look like this:

 pythonPath: path.join(__dirname, '/../python/venv/Scripts/python.exe');
AVDiv
  • 11
  • 7