Python 使用 PyBluez 进行蓝牙设备发现

1 投票
1 回答
3021 浏览
提问于 2025-04-16 08:04

我正在尝试运行这个脚本:

import PyOBEX
import bluetooth

print "performing inquiry..."

nearby_devices = bluetooth.discover_devices(lookup_names = True)

print "found %d devices" % len(nearby_devices)

for name, addr in nearby_devices:
    print " %s - %s" % (addr, name)

但是在终端里我遇到了一个“未实现”的错误。这是我得到的输出:

Last login: Sat Dec  4 20:59:06 on ttys001
You have mail.
cd '/Users/riceje7/School/NMD 430/' && '/usr/bin/pythonw'  '/Users/riceje7/School/NMD 430/BluetoohLocator.py'  && echo Exit status: $? && exit 1
Joseph-Rices-MacBook-Pro:~ riceje7$ cd '/Users/riceje7/School/NMD 430/' && '/usr/bin/pythonw'  '/Users/riceje7/School/NMD 430/BluetoohLocator.py'  && echo Exit status: $? && exit 1
Traceback (most recent call last):
File "/Users/riceje7/School/NMD 430/BluetoohLocator.py", line 2, in <module>
import bluetooth
File "/Library/Python/2.6/site-packages/bluetooth/__init__.py", line 36, in <module>
from osx import *
File "/Library/Python/2.6/site-packages/bluetooth/osx.py", line 3, in <module>
raise NotImplementedError
NotImplementedError

有没有人能帮我弄明白发生了什么,以及为什么这个脚本不能正常运行?

1 个回答

3

init.py的源代码是:

elif sys.platform == "darwin":
    from osx import *

而osx.py的源代码是:

from btcommon import *

raise NotImplementedError

这和网页上提到的内容一致,网页上只提到了Linux和Windows的实现。你可能需要联系开发者,了解他们的计划中是否有对OSX的支持。

撰写回答