PyBluez can be installed on GNU/Linux, Windows and macOS systems and is compatible with Python 2.7 and 3.,Before you install PyBluez please install the dependencies required for your system as described in the sections below.,PyBluez requires a C++ compiler installed on your system to build CPython modules.,1. Installing PyBluez 1.1. GNU/Linux Dependencies 1.2. Windows Dependencies 1.3. macOS Dependencies
pip install pybluez
pip install pybluez\[ble\]
python setup.py install
pip install - e.\[ble\]
Error: Could not find the Windows Platform SDK
pip install pybluez
python - V pip - V
pip install PyBluez - 0.22 - cp37 - cp37m - win_amd64.whl
Error: C: \Windows\ system32 > pip install pybluez - 0.22 - cp37 - cp37m - win_amd64.whl
Requirement 'pybluez-0.22-cp37-cp37m-win_amd64.whl'
looks like a filename, but t
he file does not exist
pybluez - 0.22 - cp37 - cp37m - win_amd64.whl is not a supported wheel on this platform.
This module provides access to the BSD socket interface. It is available on all modern Unix systems, Windows, MacOS, and probably additional platforms.,Depending on the system and the build options, various socket families are supported by this module.,On POSIX platforms the SO_REUSEADDR socket option is set in order to immediately reuse previous sockets which were bound on the same address and remained in TIME_WAIT state.,Return a list of network interface information (index int, name string) tuples. OSError if the system call fails.
sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM | socket.SOCK_NONBLOCK)
import socket addr = ("", 8080) # all interfaces, port 8080 if socket.has_dualstack_ipv6(): s = socket.create_server(addr, family = socket.AF_INET6, dualstack_ipv6 = True) else: s = socket.create_server(addr)
>>> socket.getaddrinfo("example.org", 80, proto=socket.IPPROTO_TCP)
[(<AddressFamily.AF_INET6: 10>, <AddressFamily.SOCK_STREAM: 1>,
6, '', ('2606:2800:220:1:248:1893:25c8:1946', 80, 0, 0)),
(<AddressFamily.AF_INET: 2>, <AddressFamily.SOCK_STREAM: 1>,
6, '', ('93.184.216.34', 80))]
import socket, array
def recv_fds(sock, msglen, maxfds):
fds = array.array("i") # Array of ints
msg, ancdata, flags, addr = sock.recvmsg(msglen, socket.CMSG_LEN(maxfds * fds.itemsize))
for cmsg_level, cmsg_type, cmsg_data in ancdata:
if cmsg_level == socket.SOL_SOCKET and cmsg_type == socket.SCM_RIGHTS:
# Append data, ignoring any truncated integers at the end.
fds.frombytes(cmsg_data[: len(cmsg_data) - (len(cmsg_data) % fds.itemsize)])
return msg, list(fds)
>>>
import socket
>>>
s1, s2 = socket.socketpair() >>>
b1 = bytearray(b '----') >>>
b2 = bytearray(b '0123456789') >>>
b3 = bytearray(b '--------------') >>>
s1.send(b 'Mary had a little lamb')
22
>>>
s2.recvmsg_into([b1, memoryview(b2)[2: 9], b3])
(22, [], 0, None) >>>
[b1, b2, b3]
[bytearray(b 'Mary'), bytearray(b '01 had a 9'), bytearray(b 'little lamb---')]
import socket, array
def send_fds(sock, msg, fds):
return sock.sendmsg([msg], [(socket.SOL_SOCKET, socket.SCM_RIGHTS, array.array("i", fds))])