Linux Min上的Python3错误“没有命名为bluetooth的模块”

2024-06-16 10:46:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试通过蓝牙将我的联想S10E连接到任天堂Wiimote。我使用的是一个简单的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 updatesudo apt-get upgrade)。我确实咨询过谷歌,我唯一能找到的官方错误是herehere,而且这两个答案都不适合我。

如何使蓝牙模块正常工作?


Tags: nameinpyimport脚本targetifaddress
3条回答

对于Ubuntu 16.04,我也有同样的问题。我安装了pybluez并修复了导入问题。我安装它使用:

sudo pip3 install pybluez

您已经安装了Python 2版本的bluez绑定。使用python2运行脚本或安装Python 3绑定。由于它们没有打包,您需要使用pip安装它们:

python3 -m pip install pybluez
sudo apt-get install bluetooth libbluetooth-dev
sudo python3 -m pip install pybluez

这对我来说对覆盆子皮3有效。

相关问题 更多 >