我正在尝试使用 npm 的 python-shell 包将 python 脚本与 Electron 应用程序链接。条件是每当我单击按钮时执行脚本。所以,假设我的目录包含:main.js (electron file)index.js (my script)index.htmlmain.py在 index.js 中,我编写了以下代码来导入 python-shell 并执行 main.py 脚本:function get_input() { var python = require("python-shell") var path = require("path") var options = { scriptPath: path.join(__dirname, './python/') } var weather = new python('main.py', options); weather.on('message', function (message) { console.log(message); })}在 index.html 中,我创建了一个按钮标签来在点击时运行这个函数:<button onclick="get_input()">Go!</button>在 main.py 中,我现在所做的就是打印“hello”。现在,当我运行时,npm start我收到以下错误:有谁知道为什么这不起作用?我看了很多关于 Electron 的文章,它们都做同样的事情,而且很有效。如果我遗漏了什么,请告诉我。
1 回答

宝慕林4294392
TA贡献2021条经验 获得超8个赞
更改var python = require("python-shell")
为const {PythonShell} = require("python-shell");
添加回答
举报
0/150
提交
取消