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

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

问题描述

我几乎搜索了整个网络(从比喻的角度来说),试图找到一种在 Mac 上通过 Python 使用蓝牙的方法.PyBluez 不兼容,Lightblue 没有得到维护(无论如何都尝试过),安装了 PyObC 框架(包括蓝牙框架),并在我的 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 中的 BLE 的功能完整、更新和完全工作的库.唯一有效的(但功能非常有限且未更新)是这里的 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天全站免登陆