Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python3 error "no module named bluetooth" on Linux Mint

I am trying to connect my Lenovo S10E to a Nintendo Wiimote via bluetooth. I am using a simple Python script, reproduced below. I am calling it from the Linux Mint (version 16, "Petra") command line using python3 find_wii.py

Script:

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")

I am receiving the error

Traceback (most recent call last):
  File "find_wii.py", line 1, in <module>
    import bluetooth
ImportError: No module named 'bluetooth'

I have installed bluez and python wrappings for it (sudo aptitude install python-bluez). I have upgraded my system (sudo apt-get update, sudo apt-get upgrade). I did consulted Google, and the only official bugs I could find are here and here, and neither of the answers worked for me.

How can I get the Bluetooth module to work?

like image 542
Qu0rk Avatar asked Jun 01 '14 22:06

Qu0rk


3 Answers

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

This worked for me on raspberry pi 3.

like image 166
greatblueherron Avatar answered Oct 07 '22 11:10

greatblueherron


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
like image 22
otus Avatar answered Oct 07 '22 13:10

otus


with Ubuntu 16.04, I had the same issue. I installed pybluez and that fixed the import issue. I installed it using:

sudo pip3 install pybluez
like image 3
Jeffrey Gong Avatar answered Oct 07 '22 13:10

Jeffrey Gong