Missing socket.AF_BLUETOOTH in Anaconda Python?

╄→гoц情女王★ 提交于 2019-12-06 05:01:03
Josh Kupershmidt

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!