【问题标题】:npm python-shell not working with electronnpm python-shell 不适用于电子
【发布时间】:2019-03-15 17:36:45
【问题描述】:

我正在尝试使用 npm 的 python-shell 包将 python 脚本与 Electron 应用程序链接。

条件是每当我点击一个按钮时执行脚本。所以,假设我的目录包含:

main.js (electron file)
index.js (my script)
index.html
main.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 的文章,它们都做同样的事情,而且很有效。如果有什么我遗漏的,请告诉我。

谢谢。

【问题讨论】:

    标签: javascript python npm electron desktop-application


    【解决方案1】:

    var python = require("python-shell")

    更改为

    const {PythonShell} = require("python-shell");

    【讨论】:

      猜你喜欢
      • 2019-08-09
      • 2017-11-29
      • 1970-01-01
      • 1970-01-01
      • 2017-09-29
      • 1970-01-01
      • 1970-01-01
      • 2020-12-10
      • 2014-11-25
      相关资源
      最近更新 更多