При попытке соединить Python и Electron.js появляется ошибка импорта - PullRequest
2 голосов
/ 28 апреля 2019

Я пишу программу на Python с библиотекой Pybluez и хочу подключить свой скрипт 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')

Это ошибка, которую я получаю:

error

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...