首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python:"AttributeError:模块' lightblue‘没有属性’查找设备‘“

Python:"AttributeError:模块' lightblue‘没有属性’查找设备‘“
EN

Stack Overflow用户
提问于 2022-04-12 09:52:53
回答 1查看 240关注 0票数 0

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

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

pip3安装pybluez

pip3安装python

python-lightblue的版本为1.0.3。下面是我的代码:

代码语言:javascript
复制
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))

当我运行这个程序时,我会发现以下错误:

代码语言:javascript
复制
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,而且我在另一个论坛上找不到任何提到这个问题的地方(也许我查找的时间不够长?)

有人知道吗?先谢谢各位:)

EN

回答 1

Stack Overflow用户

发布于 2022-12-01 08:45:47

我认为问题是在三年前的最新版本的pip注册。尝试从GitHub从主服务器安装

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

这将解决你的问题

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71840588

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档