IanHarvey / bluepy

Python interface to Bluetooth LE on Linux
Other
1.58k stars 490 forks source link

no module named bluepy.btle and no attrivbute "DefaultDelegate" #480

Open lonxx94 opened 2 years ago

lonxx94 commented 2 years ago

Hi everyone,

I try to use bluepy, my code has worked before but now i have an error.

I use "import bluepy.btle as btle"

I have setup a new Raspberry Pi3 , installed bluepy with "pip3 install bluepy", but when i try to launch my python script, I have an error that say "no module named bluepy.btle". I've tried to reinstall bluepy, but it's the same error.

So i have tried ''import bluepy as btle" , it works but now i have an other error which is "bluepy has no attribute 'DefaultDelegate'"

Do someone has the same problem ? It seems that bluepy is not installed correctly, or something like that.

Thanks for your answers, and sorry for my poor english.

maciej-napora commented 2 years ago

Hi,

It looks like python is unable to find the module files. Not much to do with the library itself.

Try:

import sys
print(sys.path)

To see the paths where the interpreter is looking for the bluepy library. There should be an entry like this leading to the bluepy module files 'btle.py' (at least on my Pi): /usr/local/lib/python3.9/dist-packages/bluepy-1.3.0-py3.9.egg/bluepy

If you find your bluepy installation directory and add it to sys.path you will be able to do e.g. ''from bluepy.btle import Scanner".

technomav commented 2 months ago

the issue is with installations, lke if you install bluepy by sudo and try to find link of the just python then you do not find bluepy. when you use sudo python then you will find bluepy. i say bluepy is king of sudo library which direct intract with hardware interface with bluez so install with sudo and use with sudo python. You can also use without sudo means install and run without sudo but in restriced permission device you will face some issues. i recommend to use with sudo.

kittenarmy commented 3 weeks ago

the issue is with installations, lke if you install bluepy by sudo and try to find link of the just python then you do not find bluepy. when you use sudo python then you will find bluepy. i say bluepy is king of sudo library which direct intract with hardware interface with bluez so install with sudo and use with sudo python. You can also use without sudo means install and run without sudo but in restriced permission device you will face some issues. i recommend to use with sudo.

On Bookworm, following instructions to install from source:

$ git clone https://github.com/IanHarvey/bluepy.git
$ cd bluepy
$ python setup.py build
$ sudo python setup.py install

I installed bluepy with sudo python, run my python script with sudo but still get this error.

kittenarmy commented 3 weeks ago

Hi,

It looks like python is unable to find the module files. Not much to do with the library itself.

Try:

import sys
print(sys.path)

To see the paths where the interpreter is looking for the bluepy library. There should be an entry like this leading to the bluepy module files 'btle.py' (at least on my Pi): /usr/local/lib/python3.9/dist-packages/bluepy-1.3.0-py3.9.egg/bluepy

If you find your bluepy installation directory and add it to sys.path you will be able to do e.g. ''from bluepy.btle import Scanner".

Thanks. I realise now I installed the bluepy in ~ so just moved it where it expects sudo mv bluepy /usr/lib/python3/dist-packages/