Linux Mint上Python3错误“找不到蓝牙模块”
我正在尝试通过蓝牙将我的联想S10E连接到任天堂的Wii遥控器。我使用了一个简单的Python脚本,下面是这个脚本的内容。我是在Linux Mint(版本16,"Petra")的命令行中用 python3 find_wii.py
来运行它。
脚本:
import bluetooth
target_name = "Nintendo RVL-CNT-01"
target_address = "00:1C:BE:29:75:7F"
nearby_devices = bluetooth.discover_devices()
for bdaddr in nearby_devices:
if target_name == bluetooth.lookup_name( bdaddr ):
target_address = bdaddr
break
if target_address is not None:
print("found target bluetooth device with address "), target_address
else:
print("could not find target bluetooth device nearby")
我遇到了这个错误:
Traceback (most recent call last):
File "find_wii.py", line 1, in <module>
import bluetooth
ImportError: No module named 'bluetooth'
我已经安装了bluez和它的Python封装(用 sudo aptitude install python-bluez
)。我也更新了我的系统(用 sudo apt-get update
和 sudo apt-get upgrade
)。我查了一下Google,找到的唯一官方的bug是这里和这里,但这些解决方案对我都没用。
我该如何让蓝牙模块正常工作呢?
3 个回答
3
在使用 Ubuntu 16.04 的时候,我也遇到了同样的问题。我安装了 pybluez,这样就解决了导入的问题。我是通过以下方式安装的:
sudo pip3 install pybluez
34
sudo apt-get install bluetooth libbluetooth-dev
sudo python3 -m pip install pybluez
这个方法在我的树莓派3上有效。
24
你已经安装了蓝牙库的Python 2版本。你可以用python2
来运行这个脚本,或者安装Python 3版本的库。因为Python 3版本的库没有打包好,所以你需要通过pip来安装它:
python3 -m pip install pybluez