通过 Python 在 Mac 上使用蓝牙

Nat*_*han 4 python macos bluetooth python-module

我几乎搜索了整个网络(打个比方来说),试图找到一种在 Mac 上通过 Python 使用蓝牙的方法。PyBluez 不兼容,Lightblue 没有得到维护(无论如何尝试),安装了 PyObC 框架(包括蓝牙框架),并在我的 MacOS 10.10.5 的 2.7.6 和 3.6.1 环境中进行了尝试。

我经常遇到类似以下的错误:

    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
Run Code Online (Sandbox Code Playgroud)

我还尝试为这两种环境重新安装所有上述模块。

我只是希望能够在一个项目中使用蓝牙而无需更改操作系统。我确信我错过了一些东西,因为我怀疑没有人用 Python 在 Mac 上编写蓝牙代码。如果存在固有的兼容性问题,是否还有其他我尚未发现的模块?

tab*_*has 5

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

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

我推荐(如果你必须使用 macOS)Node.js 库 Noble:https: //github.com/sandeepmistry/noble。功能齐全,运行良好,并且不断更新。