【发布时间】:2020-06-07 06:15:16
【问题描述】:
这是我在 electron.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)
谢谢。
【问题讨论】:
-
这意味着给定路径中的
python.exe不存在,请参阅this answer。您确定两台机器上都安装了 Python 吗? -
我不想在两台机器上都安装 python 我只想安装我的应用程序
-
好吧,那这行不通,因为
python-shell实际上会尝试生成一个 Python 进程。从您的错误消息中可以看出,这会失败,因为 Python 未安装在第二台计算机上。 -
你能给我一个解决方案,我可以在电子应用程序中使用python,而无需在所有计算机上安装python吗?
-
你不能,AFAIK。使用 Python 需要一个 Python 解释器,该解释器需要以一种或另一种方式实现,因此最好使用 Python 包/安装程序来发布您的应用程序。
标签: python node.js windows electron electron-builder