Missing socket.AF_BLUETOOTH in Anaconda Python?

后端 未结 2 932
轻奢々
轻奢々 2021-01-13 15:33

I\'m trying to use socket.AF_BLUETOOTH as explained here: https://docs.python.org/3.3/library/socket.html

I have Python 3.3.5 :: Anaconda 2.1.0 (x86_64) on Mac OS X

相关标签:
2条回答
  • 2021-01-13 15:44

    The docs say:

    Depending on the system and the build options, various socket families are supported by this module.

    And from this bit in Modules/socketmodule.c:

    #if (defined(HAVE_BLUETOOTH_H) || defined(HAVE_BLUETOOTH_BLUETOOTH_H)) && !defined(__NetBSD__) && !defined(__DragonFly__)
    #define USE_BLUETOOTH 1
    

    you'll want to make sure that HAVE_BLUETOOTH_H or USE_BLUETOOTH get set true during compilation. Which one depends by the location of your headers file. They can be in /usr/include or /usr/include/bluetooth. You can check your current settings via:

    import sysconfig
    print sysconfig.get_config_vars()['HAVE_BLUETOOTH_H']
    

    I'm guessing that returns 0 for you currently. A hint from pyconfig.h.in:

    /* Define to 1 if you have the <bluetooth/bluetooth.h> header file. */
    #undef HAVE_BLUETOOTH_BLUETOOTH_H
    

    so you should make sure that bluetooth/bluetooth.h header file is present on your system and available in your search path during compilation.

    0 讨论(0)
  • 2021-01-13 15:56

    PF_BLUETOOTH is an protocol family implemented by Linux’s bluetooth module (from BlueZ). On Linux, you create a L2CAP socket and use socket syscalls to communicate with the device (connect, bind, read, write), and the addresses have address family AF_BLUETOOTH. But this is a Linux-only socket type.

    On the Mac, you need to use the CoreBluetooth API (which uses XPC messages to the blued daemon) instead to communicate to a Bluetooth LE device.

    I’m not aware of a Python wrapper for CoreBluetooth on OS X, but if you want to see how it might look see the node.js libraries bleno or noble. Actually these libraries use the internal XPC messages which might not be too stable instead of the public API.

    0 讨论(0)
提交回复
热议问题