pythonshell和electronicbuilder在我的电脑上运行良好,但在其他电脑上不起作用



这是我的电子.js中的PythonSHELL脚本:

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]);
})
});

这是我的package.json脚本标签:

"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 .""

这是构建标签:

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

消息错误为

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)

谢谢。

答案非常清楚。您已将pythonPath链接到计算机上的解释器。你在那里给出的路径(在这种情况下-->pythonPath: 'C:/Users/abdou/AppData/Local/Programs/Python/Python38/python.exe'(只存在于你的计算机上。所以它不应该起作用。

作为一种解决方案,您可以在项目中使用python虚拟环境。然后将虚拟环境中的解释器链接到Python路径。最有可能的是,虚拟环境的路径设置如下所示:

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

相关内容

最新更新