[Record] Python3|Pybluez installation of Python3.11.0 under Windows (used to process the data of the Bluetooth module)

reference:

  1. Official installation documentation: https://github.com/pybluez/pybluez/blob/master/docs/install.rst
  2. Issue447 of the warehouse: https://github.com/pybluez/pybluez/issues/446

Some tutorials on the Internet say that python3.11.0 has to be downgraded to python3.6 and then installed. However, I checked the github issue and found that this is all nonsense. The normal installation method is like this:

  1. First, since pybluez needs to compile some cpython modules, it needs to install the C++ build environment and Windows SDK. According to the tips on the official website, you can install the Visual Studio Installer first, and then install the corresponding things here. Among them, the installation link of Visual Studio Installer is: https://developer.microsoft.com/zh-cn/windows/downloads/windows-sdk/ , click on the link and then click to download and install the program, as shown in the figure below:
    insert image description here

  2. Open the Installer, check the desktop development using C++, and click Install:
    insert image description here

  3. After completing steps 1 and 2, you can install pybluez. If you directly pip install pybluez, there will probably be error in PyBluez setup command: use_2to3 is invalid.errors. According to issue446 , just download the latest source package and install it with python setup.py install. The specific steps are as written on the official website:
    insert image description here

    The link of master.zip is: https://github.com/pybluez/pybluez/archive/master.zip
    Click the link to download, then extract it to a folder, and then run it under the folder:

    python setup.py install
    

    You can install successfully.

After installation, you can run the following program to test the installation results. Test sample:

import bluetooth

# 搜索已连接的设备
devices = bluetooth.discover_devices(lookup_names=True)

# 输出所有已连接的设备
for addr, name in devices:
    print("Found device:", name, "with address:", addr)

If nothing else, it should output a result similar to the following:
insert image description here

Guess you like

Origin blog.csdn.net/qq_46106285/article/details/129773502