javascript - I'm getting import error when I'm trying to connect Python and Electron.js
问题描述
I'm writing python program with Pybluez library and I want to connect my Python script with Electron.js
but the problem is I'm getting import error.
Does anyone know how to fix it?
I'm new to javascript and electron.js. Thank you.
Here is javascript code :
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()
}
})
Here is my python code :
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')
This is the error I'm getting :
解决方案
推荐阅读
- javascript - 在 selenium-java 中模拟输入类型“日期”的 onchange(自动日期选择器)
- javascript - 使用 node.js mysql 查询解决未定义的承诺
- python - 如何检查一组数字是否包含在更大的数字范围内?
- c - 如何从我的代码中删除“不兼容的指针类型”警告?
- javascript - 在 JS 中反应 CORS 问题,但在网络选项卡的正文中返回 200 和内容
- r - 如何创建多个工作簿,每个工作簿中有多个工作表
- office-ui-fabric - Fluent/Fabric - 是否可以以编程方式清除 NormalPeoplePicker 的输入?
- java - 如何使多个 nbm 模块的 jar 状态相同?
- python - 将变量打印到 txt 文件
- java - Spring Boot - 具有来自外部来源的属性的 ConditionalOnExpression