用Python在Mac上使用蓝牙

2024-06-08 02:13:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经搜索了整个网络(比喻地说)试图找到一种在Mac上通过Python使用蓝牙的方法。PyBluez不兼容,Lightblue未被维护(无论如何尝试),安装了PyObC框架(包括Bluetooth框架),并在带有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

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

我只想在一个项目中使用蓝牙,不需要改变操作系统。我肯定我错过了一些东西,因为我怀疑没有一个代码的蓝牙Mac与Python。如果存在固有的兼容性问题,是否还有其他模块尚未发现?


Tags: inpybuild框架环境eggmacline
1条回答
网友
1楼 · 发布于 2024-06-08 02:13:34

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

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

我建议(如果必须使用macOS)Node.js library Noble:https://github.com/sandeepmistry/noble。功能齐全,工作出色,不断更新。

相关问题 更多 >

    热门问题