Can't add "bluetooth" integration
The problem
I'm installing homeassistant via a simple python venv (I have very limited usage of HA). The installation from a few months back was working correctly, but after a recent update (and then from scratch), the bluetooth integration can't be loaded.
What version of Home Assistant Core has the issue?
core-2024.9.2
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant Core
Integration causing the issue
bluetooth
Link to integration documentation on our website
https://www.home-assistant.io/integrations/bluetooth/
Diagnostics information
No response
Example YAML snippet
bluetooth:
Anything in the logs that might be useful for us?
2024-09-22 15:28:01.881 ERROR (MainThread) [homeassistant.setup] Setup failed for 'bluetooth': Unable to import component: Exception importing homeassistant.components.bluetooth
Traceback (most recent call last):
File "/home/hass/hass/venv/lib/python3.12/site-packages/homeassistant/loader.py", line 1067, in _get_component
ComponentProtocol, importlib.import_module(self.pkg_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/hass/hass/venv/lib/python3.12/site-packages/homeassistant/util/loop.py", line 200, in protected_loop_func
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/home/hass/hass/venv/lib/python3.12/site-packages/homeassistant/components/bluetooth/__init__.py", line 27, in <module>
from habluetooth import (
File "/home/hass/hass/venv/lib/python3.12/site-packages/habluetooth/__init__.py", line 3, in <module>
from .advertisement_tracker import (
File "src/habluetooth/advertisement_tracker.py", line 1, in init habluetooth.advertisement_tracker
AttributeError: module 'habluetooth.models' has no attribute '__pyx_capi__'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/hass/hass/venv/lib/python3.12/site-packages/homeassistant/loader.py", line 1007, in async_get_component
comp = await self.hass.async_add_import_executor_job(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/hass/hass/venv/lib/python3.12/site-packages/homeassistant/loader.py", line 1078, in _get_component
raise ImportError(f"Exception importing {self.pkg_path}") from err
ImportError: Exception importing homeassistant.components.bluetooth
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/hass/hass/venv/lib/python3.12/site-packages/homeassistant/loader.py", line 1067, in _get_component
ComponentProtocol, importlib.import_module(self.pkg_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/hass/hass/venv/lib/python3.12/site-packages/homeassistant/util/loop.py", line 200, in protected_loop_func
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/home/hass/hass/venv/lib/python3.12/site-packages/homeassistant/components/bluetooth/__init__.py", line 27, in <module>
from habluetooth import (
File "/home/hass/hass/venv/lib/python3.12/site-packages/habluetooth/__init__.py", line 3, in <module>
from .advertisement_tracker import (
File "src/habluetooth/advertisement_tracker.py", line 1, in init habluetooth.advertisement_tracker
AttributeError: module 'habluetooth.models' has no attribute '__pyx_capi__'
### Additional information
I recreated the python venv, but kept the `~/.homeassistant` directory (I didn't restart all config from scratch).
I'm running on Debian Sid, on raspi4 (python 3.12.3)
Hey there @bdraco, mind taking a look at this issue as it has been labeled with an integration (bluetooth) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of bluetooth can trigger bot actions by commenting:
@home-assistant closeCloses the issue.@home-assistant rename Awesome new titleRenames the issue.@home-assistant reopenReopen the issue.@home-assistant unassign bluetoothRemoves the current integration label and assignees on the issue, add the integration domain after the command.@home-assistant add-label needs-more-informationAdd a label (needs-more-information, problem in dependency, problem in custom component) to the issue.@home-assistant remove-label needs-more-informationRemove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.
(message by CodeOwnersMention)
bluetooth documentation bluetooth source (message by IssueLinks)
Its likely that you have an old verison of habluetooth installed somewhre
Hmm, maybe, but I don't know how to really check that. Here's a small session where I check I don't have any existing module installed, and then create a new venv.
hass@hasspi:~$ python3.12 -c "import habluetooth"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'habluetooth'
hass@hasspi:~$ python3.12 -m venv new
hass@hasspi:~$ . ./new/bin/activate
(new) hass@hasspi:~$ python3.12 -c "import habluetooth"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'habluetooth'
(new) hass@hasspi:~$ pip install habluetooth
Collecting habluetooth
Using cached habluetooth-3.4.0-cp312-cp312-manylinux_2_38_aarch64.whl
....
Successfully installed PyRIC-0.1.6.3 aiooui-0.1.6 async-interrupt-1.2.0 bleak-0.22.2 bleak-retry-connector-3.5.0 bluetooth-adapters-0.19.4 bluetooth-auto-recovery-1.4.2 bluetooth-data-tools-1.20.0 btsocket-0.3.0 cffi-1.17.1 cryptography-43.0.1 dbus-fast-2.24.2 habluetooth-3.4.0 pycparser-2.22 uart-devices-0.1.0 usb-devices-0.4.5
(new) hass@hasspi:~$ pip show habluetooth
Name: habluetooth
Version: 3.4.0
Summary: High availability Bluetooth
Home-page: https://github.com/bluetooth-devices/habluetooth
Author: J. Nick Koston
Author-email: [email protected]
License:
Location: /home/hass/new/lib/python3.12/site-packages
Requires: async-interrupt, bleak, bleak-retry-connector, bluetooth-adapters, bluetooth-auto-recovery, bluetooth-data-tools
Required-by:
(new) hass@hasspi:~$ python3.12 -c "import habluetooth"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/hass/new/lib/python3.12/site-packages/habluetooth/__init__.py", line 3, in <module>
from .advertisement_tracker import (
File "src/habluetooth/advertisement_tracker.py", line 1, in init habluetooth.advertisement_tracker
AttributeError: module 'habluetooth.models' has no attribute '__pyx_capi__'
Maybe I should report it on their github project instead. I only realize now that habluetooth is not hosted in home-assistant.
3.3.2 doesn't have this behavior, but I'm not sure I can force this version...
Yes, installing 3.3.2 doesn't help, hass seems to be auto-updating the module to 3.4.0.
(venv) hass@hasspi:~/hass/venv$ pip show habluetooth
Name: habluetooth
Version: 3.3.2
Summary: High availability Bluetooth
Home-page: https://github.com/bluetooth-devices/habluetooth
Author: J. Nick Koston
Author-email: [email protected]
License:
Location: /home/hass/hass/venv/lib/python3.12/site-packages
Requires: async-interrupt, bleak, bleak-retry-connector, bluetooth-adapters, bluetooth-auto-recovery, bluetooth-data-tools
Required-by: home-assistant-bluetooth
(venv) hass@hasspi:~/hass/venv$ hass
...
KeyboardInterrupt:
^C
(venv) hass@hasspi:~/hass/venv$ pip show habluetooth
Name: habluetooth
Version: 3.4.0
Summary: High availability Bluetooth
Home-page: https://github.com/bluetooth-devices/habluetooth
Author: J. Nick Koston
Author-email: [email protected]
License:
Location: /home/hass/hass/venv/lib/python3.12/site-packages
Requires: async-interrupt, bleak, bleak-retry-connector, bluetooth-adapters, bluetooth-auto-recovery, bluetooth-data-tools
Required-by: home-assistant-bluetooth
Which cython version are you using to do the build?
Are you sure you don't have multiple copies of the habluetooth.models shared object on your system, and its loading the wrong one?
AttributeError: module 'habluetooth.models' has no attribute 'pyx_capi' seems to indicate you have mismatched versions
If I understand your question correctly, I'm using debian's package python3.12-dev (3.12.3-1).
I honestly don't think I have a dangling copy, but for the sake of being 100% sure, I'll reproduce on a different account. (I see you've just published 3.4.1, not sure this is related)
Using a different account seems to be working, so something must be broken in my setup. I'll investigate, thanks.
I still don't understand what was happening, but this is now working as expected. It's as if some venv were wrongly interacting :shrug: Probably a PEBCAK.
Thank you for your help!