'python-shell with electron-builder work fine in my computer but not working in other computer
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.
Solution 1:[1]
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');
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | AVDiv |
