1

I'm trying to run a script that is using pybluez library for Ble, but when I'm running the script I got this error:

    from gattlib import *
    ImportError:  No module named gattlib

So I tried to install the gattlib as super user with the command:

sudo pip install gattlib 

on my Raspberry but I got this error:

/usr/bin/ld: cannot find -lboost_thread
collect2: error: ld returned 1 exit status
error:command 'c++' failed with exit status 1

(O.S Raspbian running on Raspberry Pi 3)

Script:

    # bluetooth low energy scan
      from bluetooth.ble import DiscoveryService

      service = DiscoveryService()
      devices = service.discover(2)

      for address, name in devices.items():
          print("name: {}, address: {}".format(name, address))

How can I solve my problem?

5

Thats because one of the dependencies is missing. Its also better that u download it and compile it from source. install mercurial

sudo apt-get install mercurial

the clone the source of gattlib

hg clone https://bitbucket.org/OscarAcena/pygattlib
cd pygattlib
cat DEPENDS

you need to install all those dependencies, the reason you getting that error is because you didn't install libboost-thread-dev.

sudo apt-get install libboost-thread-dev

now install gattlib like any other python module.

sudo python setup.py install

That should fix it. Thats how I install it on the RPi 3

  • 1
    This does not appear to work with Python 3. – vpetersson Jan 8 '18 at 10:52
2

I have the same issue with Python 3 on a Raspberry Pi 3, and I had to do some extra steps, so I'll expand over @michael-jalloh answer:

  1. Install Mercurial

    sudo apt-get install mercurial

  2. Then, clone gattlib's source:

    hg clone https://bitbucket.org/OscarAcena/pygattlib cd pygattlib cat DEPENDS

  3. Then install glib-2.0:

    sudo apt-get install libglib2.0-dev

  4. Then install boost:

    sudo apt-get install libboost-all-dev

  5. At this point will still fail because it's looking for libboost_python-py34, and a newer version is installed libboost_python-py35, so you need to run:

    sudo ln -s /dir/to/libboost/libboost_python-py35.so /dir/to/libboost/libboost_python-py34.so

    In my device the /dir/to/libboost is /usr/lib/arm-linux-gnueabihf

  6. Now you can install gattlib

    sudo python setup.py install

Hope this helps!!!

0

This post worked for me. The key is to change the dependency to 36 version of the library.

https://stackoverflow.com/questions/41463847/got-error-while-download-gattlib-via-pip3/52271293#52271293

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.