Not initializing bluetooth_tracker because could not install requirement pybluez==0.22

I am stuck trying to figure this one out…

System:
NUC5 running Ubuntu 18.04 LTS
Docker CE running Hass.io + addons

Bluetooth works in the host system (Ubuntu):

  • hcitool dev lists the hci0 and mac address
  • hcitool scan finds my mobile phone

Hass.io logs:

Mon Jul 15 2019 22:14:18 GMT+0100 (British Summer Time)
Unable to install package pybluez==0.22: ERROR: Complete output from command /usr/local/bin/python3 -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-ybplna0e/PyBluez/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-0ibqdqyc --python-tag cp37:
  ERROR: running bdist_wheel
  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/widcomm.py -> build/lib.linux-x86_64-3.7/bluetooth
  copying bluetooth/__init__.py -> build/lib.linux-x86_64-3.7/bluetooth
  copying bluetooth/bluez.py -> build/lib.linux-x86_64-3.7/bluetooth
  copying bluetooth/osx.py -> build/lib.linux-x86_64-3.7/bluetooth
  copying bluetooth/msbt.py -> build/lib.linux-x86_64-3.7/bluetooth
  copying bluetooth/ble.py -> build/lib.linux-x86_64-3.7/bluetooth
  running build_ext
  building 'bluetooth._bluetooth' extension
  creating build/temp.linux-x86_64-3.7
  creating build/temp.linux-x86_64-3.7/bluez
  gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I./port3 -I/usr/local/include/python3.7m -c bluez/btmodule.c -o build/temp.linux-x86_64-3.7/bluez/btmodule.o
  unable to execute 'gcc': No such file or directory
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for PyBluez
    ERROR: Complete output from command /usr/local/bin/python3 -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-ybplna0e/PyBluez/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-yyhksh65/install-record.txt --single-version-externally-managed --compile:
    ERROR: 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/widcomm.py -> build/lib.linux-x86_64-3.7/bluetooth
    copying bluetooth/__init__.py -> build/lib.linux-x86_64-3.7/bluetooth
    copying bluetooth/bluez.py -> build/lib.linux-x86_64-3.7/bluetooth
    copying bluetooth/osx.py -> build/lib.linux-x86_64-3.7/bluetooth
    copying bluetooth/msbt.py -> build/lib.linux-x86_64-3.7/bluetooth
    copying bluetooth/ble.py -> build/lib.linux-x86_64-3.7/bluetooth
    running build_ext
    building 'bluetooth._bluetooth' extension
    creating build/temp.linux-x86_64-3.7
    creating build/temp.linux-x86_64-3.7/bluez
    gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I./port3 -I/usr/local/include/python3.7m -c bluez/btmodule.c -o build/temp.linux-x86_64-3.7/bluez/btmodule.o
    unable to execute 'gcc': No such file or directory
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command "/usr/local/bin/python3 -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-ybplna0e/PyBluez/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-yyhksh65/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-ybplna0e/PyBluez/

From the logs it looks like gcc is “missing”. I have attempted to fix this by adding it via:
apk add build-base python-dev withn the homeassistant container, but then it can’t build it and errors on bluetooth/bluetooth.h, which I believe is related to missing libbluetooth-dev package, so I think I now need to add bluez-dev, https://pkgs.alpinelinux.org/contents?branch=edge&name=bluez-dev&arch=x86_64&repo=main

I am just wondering if this is the right direction and why do I need those extra steps…
Is this something to do with the NUC by any chance?

EDIT:
That did it:
apk add build-base python-dev bluez-dev
pip install pybluez

Restart the container and it works!
Also removed python-dev and build-base

Can you please explain the steps to fix this error for a noob like myself, I have the same problem :frowning:

I’m not a linux guru, I just read the logs and do some googling, so the following might not be the best or most efficient way to do it, but it worked for me.

I guess it really depends if your setup is similar to mine, which is Ubuntu running directly on NUC (no VMs).
Docker CE and Hass.io piped into bash, as per the installation docs - Installing Hass.io
Some dependencies or drivers might be missing depending on type of install or hardware.
If you are running headless server, SSH into your host. If you are running Desktop, you can open Terminal app. It’s also worth updating & upgrading the packages on your host:
sudo apt update && sudo apt upgrade

Make sure Bluetooth is working correctly on your host.

a) to check for BT devices execute the following command:
hciconfig dev

b) it should return the device id,. usually hci0, if the device is not UP, run:
hciconfig hci0 up

c) if no devices listed or you are getting any errors it’s possible you don’t have BT drivers, run:
sudo apt install bluetooth and repeat steps a) and b)

d) if device is up and running, try scanning for another BT device like mobile phone (make sure it can be discovered first):
hcitool scan

If all goes well mobile phone should be visible.

Hass.io container and pybluez
If you use portainer, open console on homeassistant container, otherwise you can connect with the following command:
sudo docker exec -it homeassistant /bin/bash

e) If the logs show issue with missing compiler “gcc”, run:
apk add build-base python-dev bluez-dev

f) you should be now able to install pybluez:
pip install pybluez

g) restart homeassistant container and check the logs - in my case the errors in logs disappeared and bluetooth tracker started detecting my devices.

I hope this helps…

It’s these oddities that make it hard for me to recommend this platform to anyone. This isn’t the first time things like this have happened, and I was hoping Hass.IO would make this stuff easier. They are frustrating to say the least.

For those with Hass.io but no SSH (console login):

  1. From console: hassio login: root
  2. Type ‘login’
  3. type ‘docker exec -it homeassistant /bin/bash’

then e and f as above.
4. type ‘apk add build-base python-dev bluez-dev’
5. type ‘pip install pybluez’
6. type ‘apk del python-dev build-base’

restart by typing:

  1. exit
  2. exit
  3. ha restart
2 Likes