pip install PyBluez,安装出错

问题描述

我想使用库蓝牙,为此我想安装 PyBluez。 但是出现了如下错误

Running setup.py clean for PyBluez
Failed to build PyBluez
Installing collected packages: PyBluez
    Running setup.py install for PyBluez ... error
    ERROR: Command errored out with exit status 1:
     command: /home/zfcc/Dokumente/pyshimmer/venv/bin/python -u -c 'import io,os,sys,setuptools,tokenize; sys.argv[0] = '"'"'/tmp/pip-install-frwmijcd/pybluez_cabc8d0dc26f4997970d90ce928e4ce8/setup.py'"'"'; __file__='"'"'/tmp/pip-install-frwmijcd/pybluez_cabc8d0dc26f4997970d90ce928e4ce8/setup.py'"'"';f = getattr(tokenize,'"'"'open'"'"',open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"','"'"'\n'"'"');f.close();exec(compile(code,__file__,'"'"'exec'"'"'))' install --record /tmp/pip-record-3mafgo8m/install-record.txt --single-version-externally-managed --compile --install-headers /home/zfcc/Dokumente/pyshimmer/venv/include/site/python3.7/PyBluez
         cwd: /tmp/pip-install-frwmijcd/pybluez_cabc8d0dc26f4997970d90ce928e4ce8/
    Complete output (36 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.7
    creating build/lib.linux-x86_64-3.7/bluetooth
    copying bluetooth/btcommon.py -> build/lib.linux-x86_64-3.7/bluetooth
    copying bluetooth/ble.py -> build/lib.linux-x86_64-3.7/bluetooth
    copying bluetooth/macos.py -> build/lib.linux-x86_64-3.7/bluetooth
    copying bluetooth/bluez.py -> build/lib.linux-x86_64-3.7/bluetooth
    copying bluetooth/widcomm.py -> build/lib.linux-x86_64-3.7/bluetooth
    copying bluetooth/msbt.py -> build/lib.linux-x86_64-3.7/bluetooth
    copying bluetooth/__init__.py -> build/lib.linux-x86_64-3.7/bluetooth
    /home/zfcc/Dokumente/pyshimmer/venv/lib/python3.7/site-packages/setuptools/lib2to3_ex.py:41: SetuptoolsDeprecationWarning: 2to3 support is deprecated. If the project still requires Python 2 support,please migrate to a single-codebase solution or employ an independent conversion process.
      SetuptoolsDeprecationWarning)
    Fixing build/lib.linux-x86_64-3.7/bluetooth/btcommon.py build/lib.linux-x86_64-3.7/bluetooth/ble.py build/lib.linux-x86_64-3.7/bluetooth/macos.py build/lib.linux-x86_64-3.7/bluetooth/bluez.py build/lib.linux-x86_64-3.7/bluetooth/widcomm.py build/lib.linux-x86_64-3.7/bluetooth/msbt.py build/lib.linux-x86_64-3.7/bluetooth/__init__.py
    Skipping optional fixer: buffer
    Skipping optional fixer: idioms
    Skipping optional fixer: set_literal
    Skipping optional fixer: ws_comma
    Fixing build/lib.linux-x86_64-3.7/bluetooth/btcommon.py build/lib.linux-x86_64-3.7/bluetooth/ble.py build/lib.linux-x86_64-3.7/bluetooth/macos.py build/lib.linux-x86_64-3.7/bluetooth/bluez.py build/lib.linux-x86_64-3.7/bluetooth/widcomm.py build/lib.linux-x86_64-3.7/bluetooth/msbt.py build/lib.linux-x86_64-3.7/bluetooth/__init__.py
    Skipping optional fixer: buffer
    Skipping optional fixer: idioms
    Skipping optional fixer: set_literal
    Skipping optional fixer: ws_comma
    running build_ext
    building 'bluetooth._bluetooth' extension
    creating build/temp.linux-x86_64-3.7
    creating build/temp.linux-x86_64-3.7/bluez
    x86_64-unkNown-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -O2 -g -pipe -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC -I./port3 -I/home/zfcc/Dokumente/pyshimmer/venv/include -I/usr/include/python3.7m -c bluez/btmodule.c -o build/temp.linux-x86_64-3.7/bluez/btmodule.o
    In Datei,eingebunden von bluez/btmodule.c:20:
    bluez/btmodule.h:5:10: schwerwiegender Fehler: bluetooth/bluetooth.h: Datei oder Verzeichnis nicht gefunden
        5 | #include <bluetooth/bluetooth.h>
          |          ^~~~~~~~~~~~~~~~~~~~~~~
    Kompilierung beendet.
    error: command 'x86_64-unkNown-linux-gnu-gcc' Failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/zfcc/Dokumente/pyshimmer/venv/bin/python -u -c 'import io,'"'"'exec'"'"'))' install --record /tmp/pip-record-3mafgo8m/install-record.txt --single-version-externally-managed --compile --install-headers /home/zfcc/Dokumente/pyshimmer/venv/include/site/python3.7/PyBluez Check the logs for full command output.

我正在寻找类似的错误并尝试了一些类似的情况,但没有任何效果。 我还从 http://www.bluez.org/ 安装了 bluez。 我正在使用 Linux Mint 20 Cinnamon。我使用了命令 pip install PyBluez

我只想测试我的设备是否仍处于连接状态。因为有时设备会失去连接,Python Skrpt 会抛出错误。为了找出连接状态,我想使用图书馆蓝牙。但是,如果有人有另一种可能性来检查我的设备的状态,那也没关系。 我将我的设备与 sudo rfcomm bind 0 <Adress> 绑定。使用 hcitool con 终端找不到设备为什么这种解决方案对我不起作用:

import subprocess as sp

stdoutdata = sp.getoutput("hcitool con")

if "XX:XX:XX:XX:XX:XX" in stdoutdata.split():
    print("Bluetooth device is connected")

服务蓝牙状态为:

~$ service bluetooth status
● bluetooth.service - Bluetooth service
     Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor pre>
     Active: active (running) since Wed 2021-05-19 16:04:15 CEST; 5min ago
       Docs: man:bluetoothd(8)
   Main PID: 740 (bluetoothd)
     Status: "Running"
      Tasks: 1 (limit: 18949)
     Memory: 2.4M
     CGroup: /system.slice/bluetooth.service
             └─740 /usr/local/libexec/bluetooth/bluetoothd

Mai 19 16:04:15 C02L23NB0124 systemd[1]: Started Bluetooth service.
Mai 19 16:04:15 C02L23NB0124 bluetoothd[740]: Starting SDP server
Mai 19 16:04:15 C02L23NB0124 bluetoothd[740]: Bluetooth management interface 1.>
Mai 19 16:04:15 C02L23NB0124 bluetoothd[740]: src/adapter.c:reset_adv_monitors_>
Mai 19 16:04:18 C02L23NB0124 bluetoothd[740]: Endpoint registered: sender=:1.50>
Mai 19 16:04:18 C02L23NB0124 bluetoothd[740]: Endpoint registered: sender=:1.50>
Mai 19 16:06:28 C02L23NB0124 bluetoothd[740]: Endpoint unregistered: sender=:1.>
Mai 19 16:06:28 C02L23NB0124 bluetoothd[740]: Endpoint unregistered: sender=:1.>
Mai 19 16:06:29 C02L23NB0124 bluetoothd[740]: Endpoint registered: sender=:1.80>
Mai 19 16:06:29 C02L23NB0124 bluetoothd[740]: Endpoint registered: sender=:1.80>
lines 1-21/21 (END)...skipping...
● bluetooth.service - Bluetooth service
     Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-05-19 16:04:15 CEST; 5min ago
       Docs: man:bluetoothd(8)
   Main PID: 740 (bluetoothd)
     Status: "Running"
      Tasks: 1 (limit: 18949)
     Memory: 2.4M
     CGroup: /system.slice/bluetooth.service
             └─740 /usr/local/libexec/bluetooth/bluetoothd

Mai 19 16:04:15 C02L23NB0124 systemd[1]: Started Bluetooth service.
Mai 19 16:04:15 C02L23NB0124 bluetoothd[740]: Starting SDP server
Mai 19 16:04:15 C02L23NB0124 bluetoothd[740]: Bluetooth management interface 1.14 initialized
Mai 19 16:04:15 C02L23NB0124 bluetoothd[740]: src/adapter.c:reset_adv_monitors_complete() Failed to reset Adv Monitors: UnkNown Command (0x01)
Mai 19 16:04:18 C02L23NB0124 bluetoothd[740]: Endpoint registered: sender=:1.50 path=/MediaEndpoint/A2DPSink/sbc
Mai 19 16:04:18 C02L23NB0124 bluetoothd[740]: Endpoint registered: sender=:1.50 path=/MediaEndpoint/A2DPSource/sbc
Mai 19 16:06:28 C02L23NB0124 bluetoothd[740]: Endpoint unregistered: sender=:1.50 path=/MediaEndpoint/A2DPSink/sbc
Mai 19 16:06:28 C02L23NB0124 bluetoothd[740]: Endpoint unregistered: sender=:1.50 path=/MediaEndpoint/A2DPSource/sbc
Mai 19 16:06:29 C02L23NB0124 bluetoothd[740]: Endpoint registered: sender=:1.80 path=/MediaEndpoint/A2DPSink/sbc
Mai 19 16:06:29 C02L23NB0124 bluetoothd[740]: Endpoint registered: sender=:1.80 path=/MediaEndpoint/A2DPSource/sbc

我的蓝牙版本是 5.58

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)