× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [1 lines of output]
error in PyBluez setup command: use_2to3 is invalid.
[end of output]
Preparing metadata (setup.py) … error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [1 lines of output]
error in PyBluez setup command: use_2to3 is invalid.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
正常通过window11 python 3.11安装pybluez,尝试第一次安装过程出现缺少,window SDK,于是去官网下载了SDK.先下载。之后安装,然后下载之后install SDK智能安装到c盘。安装后重新启动依旧出现该问题。
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [1 lines of output]
error in PyBluez setup command: use_2to3 is invalid.
经过查找其实就是版本问题,但是现在已经很难匹配了。不能直接通过pip进行识别了,因此本人采取以下办法。
上到pybluez官网,github进行下载。
http://t.csdnimg.cn/CnXRH
这个博主中的地址。
然后解压文件夹。
之后,通过cmd,cd到解压后存在setup.py的位置,并且配置好当前环境。conda activate envir.
之后,正常安装过程。使用语句
python setup.py install
import time
from bluetooth import *
import bluetooth
#列表,用于存放已搜索过的蓝牙名称
alreadyFound = []
#搜索蓝牙
def findDevs():
foundDevs = discover_devices(lookup_names=True)
# 循环遍历,如果在列表中存在的就不打印
for (addr,name) in foundDevs:
if addr not in alreadyFound:
print("[*]蓝牙设备:" + str(name))
print("[+]蓝牙MAC:" + str(addr))
# 新增的设备mac地址定到列表中,用于循环搜索时过滤已打印的设备
alreadyFound.append(addr)
# 循环执行,每5秒执行一次
findDevs()
time.sleep(3)
port = 1
sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect(("98:DA:E0:01:1D:9E", port))
message = "$1,0,0,0,0,0,0,0,0,0#"
sock.send(message)
sock.close()
print("send message")