在Mac上使用Python在蓝牙上使用蓝牙 [英] Utilising bluetooth on Mac with Python

查看:356
本文介绍了在Mac上使用Python在蓝牙上使用蓝牙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上已经遍及整个网络(隐喻地说),试图找到一种在Mac上通过Python使用蓝牙的方法. PyBluez不兼容,Lightblue未得到维护(无论如何尝试),未安装PyObC框架(包括Bluetooth框架),并尝试在我的2.7.6和3.6.1环境中使用MacOS 10.10.5.

I've practically scoured the entire web (metaphorically speaking) trying to find a way to work with Bluetooth via Python on Mac. PyBluez is not compatible, Lightblue is not being maintained (tried regardless), installed the PyObC framework (incl Bluetooth Framework), and attempted in both my 2.7.6 and 3.6.1 environments with MacOS 10.10.5.

我经常会收到类似于以下内容的错误:

I often get errors similar to the below:

    Traceback (most recent call last):
  File "/Users/***/PycharmProjects/Bluey/main.py", line 1, in <module>
    import bluetooth
  File "build/bdist.macosx-10.10-intel/egg/bluetooth/__init__.py", line 47, in <module>
  File "build/bdist.macosx-10.10-intel/egg/bluetooth/osx.py", line 1, in <module>
  File "build/bdist.macosx-10.10-intel/egg/lightblue/__init__.py", line 160, in <module>
  File "build/bdist.macosx-10.10-intel/egg/lightblue/_lightblue.py", line 31, in <module>
  File "build/bdist.macosx-10.10-intel/egg/lightblue/_macutil.py", line 169, in <module>
objc.BadPrototypeError: Objective-C expects 1 arguments, Python argument has 2 arguments for <unbound selector sleep of BBCocoaSleeper at 0x103cdc030>

Process finished with exit code 1

我还尝试针对两种环境重新安装所有上述模块.

I've also tried reinstalling all the aforementioned modules for both environments.

我只希望能够使用蓝牙而无需为一个项目更改操作系统.我敢肯定我错过了一些东西,因为我怀疑没有Mac上使用Python的蓝牙代码.如果存在与生俱来的兼容性问题,是否还有我尚未发现的其他模块?

I just want to be able to work with Bluetooth w/o changing OSs for one project. I'm sure I've missed something since I doubt no-one codes for Bluetooth on Mac with Python. If there are inherent compatibility issues, is there another module that I have yet to discover?

推荐答案

在macOS上的Python中,没有任何功能完整,更新且完全可用的库.唯一可行的(但功能非常有限且未更新)是此处的Adafruit库: https://github.com/adafruit/Adafruit_Python_BluefruitLE

There aren't any feature complete, updated, and fully working libraries for BLE in Python on macOS. The only one that works (but is very limited in functionality and not updated) is the Adafruit library here: https://github.com/adafruit/Adafruit_Python_BluefruitLE

您可能想尝试使用PyObjC(这是Adafruit库所使用的)来查看是否可以构建自己的BLE库/脚本.

You may want to try to use PyObjC (thats what the Adafruit library uses) to see if you can build your own BLE library/script.

我建议(如果必须使用macOS的话)是Node.js库Noble: https://github.com/sandeepmistry/noble .功能齐全,效果很好,并且会不断更新.

I'd recommend (if you have to use macOS) is the Node.js library Noble: https://github.com/sandeepmistry/noble. Full-featured, works great and is continuously updated.

这篇关于在Mac上使用Python在蓝牙上使用蓝牙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆