为了账号安全,请及时绑定邮箱和手机立即绑定

npm python-shell 不适用于电子

npm python-shell 不适用于电子

收到一只叮咚 2021-07-09 17:02:14
我正在尝试使用 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");


查看完整回答
反对 回复 2021-07-13
  • 1 回答
  • 0 关注
  • 344 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号