Utilising bluetooth on Mac with Python

13,381

There aren't any feature complete, updated, and fully working libraries for BLE in Python on macOS. The only one that works (but is very limited in functionality and not updated) is the Adafruit library here: https://github.com/adafruit/Adafruit_Python_BluefruitLE

You may want to try to use PyObjC (thats what the Adafruit library uses) to see if you can build your own BLE library/script.

I'd recommend (if you have to use macOS) is the Node.js library Noble: https://github.com/sandeepmistry/noble. Full-featured, works great and is continuously updated.

Share:
13,381
Nathan
Author by

Nathan

Updated on July 31, 2022

Comments

  • Nathan
    Nathan almost 2 years

    I've practically scoured the entire web (metaphorically speaking) trying to find a way to work with Bluetooth via Python on Mac. PyBluez is not compatible, Lightblue is not being maintained (tried regardless), installed the PyObC framework (incl Bluetooth Framework), and attempted in both my 2.7.6 and 3.6.1 environments with MacOS 10.10.5.

    I often get errors similar to the below:

        Traceback (most recent call last):
      File "/Users/***/PycharmProjects/Bluey/main.py", line 1, in <module>
        import bluetooth
      File "build/bdist.macosx-10.10-intel/egg/bluetooth/__init__.py", line 47, in <module>
      File "build/bdist.macosx-10.10-intel/egg/bluetooth/osx.py", line 1, in <module>
      File "build/bdist.macosx-10.10-intel/egg/lightblue/__init__.py", line 160, in <module>
      File "build/bdist.macosx-10.10-intel/egg/lightblue/_lightblue.py", line 31, in <module>
      File "build/bdist.macosx-10.10-intel/egg/lightblue/_macutil.py", line 169, in <module>
    objc.BadPrototypeError: Objective-C expects 1 arguments, Python argument has 2 arguments for <unbound selector sleep of BBCocoaSleeper at 0x103cdc030>
    
    Process finished with exit code 1
    

    I've also tried reinstalling all the aforementioned modules for both environments.

    I just want to be able to work with Bluetooth w/o changing OSs for one project. I'm sure I've missed something since I doubt no-one codes for Bluetooth on Mac with Python. If there are inherent compatibility issues, is there another module that I have yet to discover?

    • tabchas
      tabchas almost 7 years
      There aren't any complete libraries for BLE on macOS.