蟒蛇浅蓝色:"AttributeError: module 'lightblue' has no attribute 'finddevices'"



大家好,希望你们过得好!

我正在尝试编写一个Python(3.8.9(脚本,以便我的计算机检测到它能找到的每一个蓝牙设备,并向我提供它找到的设备列表。然后,我用安装了pybluezlightblue

pip3安装pybluez

pip3安装python lightblue

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,并且我在另一个论坛上找不到任何关于这个问题的提及(也许我查找的时间不够长?(

有人知道吗?提前感谢!:-(

我认为问题出在pip注册表中3年前的最新版本中。尝试从GitHub 的master安装

pip安装git+https://github.com/pybluez/pybluez.git

这将解决您的问题

相关内容

最新更新