树莓派pybluez填坑

来自https://www.hsli.top

安装pybluez
安装libbluetooth-dev避免报错

sudo apt-get install libbluetooth-dev

安装pybluez

sudo apt-get install pybluez

例子:pybluz 查询蓝牙

1
2
3
4
5
6
import bluetooth
print("performing inquiry...")
nearby_devices = bluetooth.discover_devices(lookup_names = True)
print("found %d devices" % len(nearby_devices))
for addr, name in nearby_devices:
print(" %s - %s" % (addr, name))

1、import bluetooth
报错:no module named bluetooth
原因及解决方法:

You’ve installed the Python 2 version of the bluez bindings. Either run the script using
python2 or install the Python 3 bindings. Since they aren’t packaged, you would need to install them using pip:
python3 -m pip install pybluez

2、no module named gattlib
解决方法:
sudo apt-get install libboost-python-dev libboost-thread-dev libbluetooth-dev libglib2.0-dev

如果文章有用,请随意打赏