AnthonyKNorman / Xiaomi_BLE_Temperature_Display_for_HA

50 stars 15 forks source link

error with ble_scan_example.py - No module named 'bluepy' using python3 #5

Closed woody4165 closed 4 years ago

woody4165 commented 4 years ago

Hi

I've just installed a pi zero wh with latest raspbian lite and copied the three .py files from here, changed the MQTT ip address and trying to execute the ble_scan_example.py

pi@raspberrypi:~ $ sudo python3 ble_scan_example.py 
Traceback (most recent call last):
  File "ble_scan_example.py", line 1, in <module>
    from bluepy.btle import Scanner, DefaultDelegate
ModuleNotFoundError: No module named 'bluepy'

What should I check to solve this error?

I've also installed bluepy wirh sudo pip install bluepy

and rebooted but still same error

Thanks

PS: if I call with sudo python ble_scan_example.py

it works.
Strange!

AnthonyKNorman commented 4 years ago

Not so strange! This is because you installed bluepy with pip. This installs it for Python version 2. When you run it with 'python' that also is version 2, so it runs. What you need to do is use

$ sudo apt-get install python3-pip libglib2.0-dev
$ sudo pip3 install bluepy

and then it will work with python3. You should avoid using python version 2 as it has now been made end of life. Let me know if this works.

woody4165 commented 4 years ago

Thanks @AnthonyKNorman

I haven't thought about pip3!

Now it's working fine.