。
大家好,希望你们做得好!
我正在尝试编写一个Python (3.8.9)脚本,这样我的计算机就可以检测到它能找到的每一个蓝牙设备,并向我提供它找到的设备列表。然后,我安装了pybluez和lightblue
pip3安装pybluez
和
pip3安装python
python-lightblue的版本为1.0.3。下面是我的代码:
import bluetooth
def scan():
print("Scanning for bluetooth devices:")
devices = bluetooth.discover_devices(lookup_names = True, lookup_class = True)
number_of_devices = len(devices)
print(number_of_devices," devices found")
for addr, name, device_class in devices:
print("\n")
print("Device:")
print("Device Name: %s" % (name))当我运行这个程序时,我会发现以下错误:
Traceback (most recent call last):
File "bluetooth_detect.py", line 16, in <module>
scan()
File "bluetooth_detect.py", line 5, in scan
devices = bluetooth.discover_devices(lookup_names = True, lookup_class = True)
File "/Users/<my_name>/Library/Python/3.8/lib/python/site-packages/bluetooth/macos.py", line 12, in discover_devices
devices = lightblue.finddevices(getnames=lookup_names, length=duration)
AttributeError: module 'lightblue' has no attribute 'finddevices'然而,当我查看互联网上的文档时,模块lightblue确实有属性finddevices,而且我在另一个论坛上找不到任何提到这个问题的地方(也许我查找的时间不够长?)
有人知道吗?先谢谢各位:)
发布于 2022-12-01 08:45:47
https://stackoverflow.com/questions/71840588
复制相似问题