HA debug log ERRORs with ImportError: cannot import name 'resource_filename' from 'pkg_resources' (/usr/local/lib/python3.12/site-packages/pkg_resources/__init__.py)

HAOS on Rpi-4

  • Core 2024.5.0
  • Supervisor 2024.04.4
  • Operating System 12.2
  • Frontend 20240501.0

HA started with openweathermap not loading but looking into the HA logs, it seems the problem is not integration specific. Log pasted below. Seems like HA is looking for python in 3.12 while installed is 3.11:

python --version
Python 3.11.8

Logger: homeassistant.setup
Source: setup.py:322
First occurred: 9:30:43 PM (1 occurrences)
Last logged: 9:30:43 PM

Setup failed for 'openweathermap': Unable to import component: cannot import name 'resource_filename' from 'pkg_resources' (/usr/local/lib/python3.12/site-packages/pkg_resources/__init__.py)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 976, in async_get_component
    comp = await self.hass.async_add_import_executor_job(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1036, in _get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 144, in protected_loop_func
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/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 "/usr/src/homeassistant/homeassistant/components/openweathermap/__init__.py", line 8, in <module>
    from pyowm import OWM
  File "/usr/local/lib/python3.12/site-packages/pyowm/__init__.py", line 4, in <module>
    from pyowm.owm import OWM
  File "/usr/local/lib/python3.12/site-packages/pyowm/owm.py", line 14, in <module>
    from pyowm.commons import cityidregistry
  File "/usr/local/lib/python3.12/site-packages/pyowm/commons/cityidregistry.py", line 5, in <module>
    from pkg_resources import resource_filename
ImportError: cannot import name 'resource_filename' from 'pkg_resources' (/usr/local/lib/python3.12/site-packages/pkg_resources/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 322, in _async_setup_component
    component = await integration.async_get_component()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 996, in async_get_component
    self._component_future.result()
  File "/usr/src/homeassistant/homeassistant/loader.py", line 988, in async_get_component
    comp = self._get_component()
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1036, in _get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 144, in protected_loop_func
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/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 "/usr/src/homeassistant/homeassistant/components/openweathermap/__init__.py", line 8, in <module>
    from pyowm import OWM
  File "/usr/local/lib/python3.12/site-packages/pyowm/__init__.py", line 4, in <module>
    from pyowm.owm import OWM
  File "/usr/local/lib/python3.12/site-packages/pyowm/owm.py", line 14, in <module>
    from pyowm.commons import cityidregistry
  File "/usr/local/lib/python3.12/site-packages/pyowm/commons/cityidregistry.py", line 5, in <module>
    from pkg_resources import resource_filename
ImportError: cannot import name 'resource_filename' from 'pkg_resources' (/usr/local/lib/python3.12/site-packages/pkg_resources/__init__.py)