我正在使用Pybluez库编写python程序,并且想将Python脚本与Electron.js
连接,但是问题是我遇到导入错误。
有人知道如何解决吗?
我是javascript和electron.js的新手。谢谢。
这是JavaScript代码:
const ElectronTitlebarWindows = require('electron-titlebar-windows');
const {PythonShell} = require("python-shell");
//----------------Functions------------------------------------------------
function createWindow () {
window = new BrowserWindow({width: 900, height: 600,icon: 'pressure.png'})
window.loadFile('index.html')
window.setMenu(null)
PythonShell.run('SensorApp.py', null, function (err) {
if (err) throw err;
console.log('finished');
});
}
app.on('ready', createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
这是我的python代码:
import bluetooth
import sys
class BTcommucation():
def find_device(self):
devices = bluetooth.discover_devices(lookup_names=True)
print("I have found " + str(len(devices)) + " devices!")
for address, name in devices:
print(address + " " + name)
def connect_device(self,addressMAC, port=1 ):
socket = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
socket.connect((addressMAC, port))
while(True):
print("Enter your command:")
text = input()
if text == "quit":
break
socket.send(text.encode())
socket.close()
print("Connection lost or quit")
bt_adapter = BTcommucation()
bt_adapter.connect_device('98:D3:37:00:A9:26')
这是我得到的错误: