我正在嘗試使用 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”?,F在,當我運行時,npm start我收到以下錯誤:有誰知道為什么這不起作用?我看了很多關于 Electron 的文章,它們都做同樣的事情,而且很有效。如果我遺漏了什么,請告訴我。
1 回答

寶慕林4294392
TA貢獻2021條經驗 獲得超8個贊
更改var python = require("python-shell")
為const {PythonShell} = require("python-shell");
添加回答
舉報
0/150
提交
取消