• python使用蓝牙库选择


    蓝牙库选择

    pybluez

    项目地址:https://github.com/pybluez/pybluez
    文档地址:https://pybluez.readthedocs.io/en/latest/index.html
    蓝牙支持:经典蓝牙 / BLE蓝牙【仅Linux】
    平台支持:

    LinuxRaspberry PimacOSWindows
    ✔️✔️✔️✔️

    bluepy

    项目地址:https://github.com/IanHarvey/bluepy
    蓝牙支持:BLE蓝牙【仅Linux
    平台支持:Linux

    gatt-python

    项目地址:https://github.com/getsenic/gatt-python
    蓝牙支持:BLE蓝牙【仅Linux】
    平台支持:Linux

    PySide6.QtBluetooth

    Qt for Python的蓝牙,文档 https://doc.qt.io/qtforpython-6/PySide6/QtBluetooth/index.html
    蓝牙支持 / 平台支持:
    在这里插入图片描述

    bleak

    项目地址:https://github.com/hbldh/bleak
    文档地址:https://bleak.readthedocs.io/en/latest/
    蓝牙支持:BLE蓝牙【windows 10/Linux】
    平台支持:

    • Supports Windows 10, version 16299 (Fall Creators Update) or greater
    • Supports Linux distributions with BlueZ >= 5.43 (See Linux backend for more details)
    • OS X/macOS support via Core Bluetooth API, from at least OS X version 10.11

    pybluez安装

    pip安装

    pip install pybluez
    
    • 1

    具体安装细节详见 https://github.com/pybluez/pybluez/blob/master/docs/install.rst

    常见错误

    错误一:使用废弃的 use_2to3 报错

    安装错误

    $ pip install --upgrade pybluez
    Collecting pybluez
      Using cached PyBluez-0.23.tar.gz (97 kB)
      Installing build dependencies ... done
      Getting requirements to build wheel ... error
      error: subprocess-exited-with-error
    
      × Getting requirements to build wheel 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: subprocess-exited-with-error
    
    × Getting requirements to build wheel did not run successfully.
    │ exit code: 1
    ╰─> See above for output.
    
    note: This error originates from a subprocess, and is likely not a problem with pip.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    错误原因详见:PyBluez Issues#431
    解决方案:使用如下命令从源代码安装

    pip install git+https://github.com/pybluez/pybluez.git#egg=pybluez
    
    • 1

    错误二:源码安装没有对应的Microsoft Visual C++ 14.0库

    $ pip install git+https://github.com/pybluez/pybluez.git#egg=pybluez
    Collecting pybluez
      Cloning https://github.com/pybluez/pybluez.git to c:\users\acer\appdata\local\temp\pip-install-mki8zoy9\pybluez_5660e54d6b4643c2a85546348792a2ee
      Running command git clone --filter=blob:none --quiet https://github.com/pybluez/pybluez.git 'C:\Users\acer\AppData\Local\Temp\pip-install-mki8zoy9\pybluez_5660e54d6b4643c2a85546348792a2ee'
      Resolved https://github.com/pybluez/pybluez.git to commit 4d46ce14d9e888e3b0c65d5d3ba2a703f8e5e861
      Installing build dependencies ... done
      Getting requirements to build wheel ... done
      Preparing metadata (pyproject.toml) ... done
    Building wheels for collected packages: pybluez
      Building wheel for pybluez (pyproject.toml) ... error
      error: subprocess-exited-with-error
    
      × Building wheel for pybluez (pyproject.toml) did not run successfully.
      │ exit code: 1
      ╰─> [15 lines of output]
          running bdist_wheel
          running build
          running build_py
          creating build
          creating build\lib.win-amd64-cpython-311
          creating build\lib.win-amd64-cpython-311\bluetooth
          copying bluetooth\ble.py -> build\lib.win-amd64-cpython-311\bluetooth
          copying bluetooth\bluez.py -> build\lib.win-amd64-cpython-311\bluetooth
          copying bluetooth\btcommon.py -> build\lib.win-amd64-cpython-311\bluetooth
          copying bluetooth\macos.py -> build\lib.win-amd64-cpython-311\bluetooth
          copying bluetooth\msbt.py -> build\lib.win-amd64-cpython-311\bluetooth
          copying bluetooth\__init__.py -> build\lib.win-amd64-cpython-311\bluetooth
          running build_ext
          building 'bluetooth._msbt' extension
          error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
          [end of output]
    
      note: This error originates from a subprocess, and is likely not a problem with pip.
      ERROR: Failed building wheel for pybluez
    Failed to build pybluez
    ERROR: Could not build wheels for pybluez, which is required to install pyproject.toml-based projects
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    解决方式:从https://visualstudio.microsoft.com/visual-cpp-build-tools/下载Microsoft C++ 生成工具安装后重新执行指令。

    在这里插入图片描述

    $ pip install git+https://github.com/pybluez/pybluez.git#egg=pybluez
    Collecting pybluez
      Cloning https://github.com/pybluez/pybluez.git to c:\users\acer\appdata\local\temp\pip-install-n2w1b_hj\pybluez_e8804231d731412e974e0d8e7a4a56f4
      Running command git clone --filter=blob:none --quiet https://github.com/pybluez/pybluez.git 'C:\Users\acer\AppData\Local\Temp\pip-install-n2w1b_hj\pybluez_e8804231d731412e974e0d8e7a4a56f4'
      Resolved https://github.com/pybluez/pybluez.git to commit 4d46ce14d9e888e3b0c65d5d3ba2a703f8e5e861
      Installing build dependencies ... done
      Getting requirements to build wheel ... done
      Preparing metadata (pyproject.toml) ... done
    Building wheels for collected packages: pybluez
      Building wheel for pybluez (pyproject.toml) ... done
      Created wheel for pybluez: filename=PyBluez-0.30-cp311-cp311-win_amd64.whl size=38986 sha256=a37ebad09bb1196f44d7a90900694c0ac1802c83efef5d3766a908dc6b23fd84
      Stored in directory: C:\Users\acer\AppData\Local\Temp\pip-ephem-wheel-cache-dtnnjqfc\wheels\99\fe\57\0c682c42e37c808dc69125bf83b302f94976743c8cb038a845      
    Successfully built pybluez
    Installing collected packages: pybluez
    Successfully installed pybluez-0.30
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
  • 相关阅读:
    Linux常见命令总结
    DispatcherServlet类源码简介说明
    vscode中设置vue用户代码片段
    Spring Boot (三)
    ​面试经典150题——LRU 缓存
    【uniapp】确认弹出框,选择确定和取消
    Vue3+elementplus搭建通用管理系统实例八:通用表格实现中
    Netty-bytebuf
    HttpRunner初体验
    SpringBoot整合RocketMq
  • 原文地址:https://blog.csdn.net/u013564470/article/details/133274134