FL550 / dwd_weather

Deutscher Wetterdienst integration for Home-Assistant
MIT License
192 stars 12 forks source link

Unable to import component: cannot import name 'MarkerShape' from 'simple_dwd_weatherforecast.dwdmap #155

Open Ra72xx opened 5 days ago

Ra72xx commented 5 days ago

Version of home_assistant

2024.10.1 Container install

Version of the custom_component

2.1.15

Describe the bug

Title says it all: The custom integration cannot be loaded at all because of this error.

Debug log

No debug log, just normal error log.


Logger: homeassistant.setup
Quelle: setup.py:334
Erstmals aufgetreten: 17:04:53 (1 Vorkommnisse)
Zuletzt protokolliert: 17:04:53

Setup failed for custom integration 'dwd_weather': Unable to import component: cannot import name 'MarkerShape' from 'simple_dwd_weatherforecast.dwdmap' (/config/deps/lib/python3.12/site-packages/simple_dwd_weatherforecast/dwdmap.py)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1007, 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 1067, in _get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 200, 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 "/config/custom_components/dwd_weather/__init__.py", line 14, in <module>
    from .connector import DWDMapData, DWDWeatherData
  File "/config/custom_components/dwd_weather/connector.py", line 34, in <module>
    from .const import (
  File "/config/custom_components/dwd_weather/const.py", line 6, in <module>
    from simple_dwd_weatherforecast.dwdmap import MarkerShape
ImportError: cannot import name 'MarkerShape' from 'simple_dwd_weatherforecast.dwdmap' (/config/deps/lib/python3.12/site-packages/simple_dwd_weatherforecast/dwdmap.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 334, in _async_setup_component
    component = await integration.async_get_component()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1027, in async_get_component
    self._component_future.result()
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1019, in async_get_component
    comp = self._get_component()
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1067, in _get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 200, 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 "/config/custom_components/dwd_weather/__init__.py", line 14, in <module>
    from .connector import DWDMapData, DWDWeatherData
  File "/config/custom_components/dwd_weather/connector.py", line 34, in <module>
    from .const import (
  File "/config/custom_components/dwd_weather/const.py", line 6, in <module>
    from simple_dwd_weatherforecast.dwdmap import MarkerShape
ImportError: cannot import name 'MarkerShape' from 'simple_dwd_weatherforecast.dwdmap' (/config/deps/lib/python3.12/site-packages/simple_dwd_weatherforecast/dwdmap.py)
FL550 commented 5 days ago

Thanks for reporting, I'll have a look.

Links2004 commented 2 days ago

Having the same problem with Home Assistant 2024.10.2 (Container)

u-lehner commented 2 days ago

Same here, also with Home Assistant 2024.10.2 running in a container.

FL550 commented 2 days ago

I'll have a look later.

@u-lehner @Links2004 @Ra72xx By container you mean the official docker image?

Links2004 commented 2 days ago

yes i use the official docker image

FL550 commented 2 days ago

Very strange, I develop and test within the homeassistant docker image. My only guess is, that the import isn't allowed in the const file. I therefore moved this now into the connector file. Let's see if this solves the issue. I'll release it later.

chr-fritz commented 1 day ago

Hi @FL550,

it looks like that the version 2.1.16 did not solved the problem.

Logger: homeassistant.setup
Quelle: setup.py:334
Erstmals aufgetreten: 21:41:46 (1 Vorkommnisse)
Zuletzt protokolliert: 21:41:46

Setup failed for custom integration 'dwd_weather': Unable to import component: Exception importing custom_components.dwd_weather
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1067, in _get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 200, 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 "/config/custom_components/dwd_weather/__init__.py", line 14, in <module>
    from .connector import DWDMapData, DWDWeatherData
  File "/config/custom_components/dwd_weather/connector.py", line 81, in <module>
    CONF_MAP_HOMEMARKER_SHAPE_CIRCLE: dwdmap.MarkerShape.CIRCLE,
                                      ^^^^^^^^^^^^^^^^^^
AttributeError: module 'simple_dwd_weatherforecast.dwdmap' has no attribute 'MarkerShape'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1007, 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 1078, in _get_component
    raise ImportError(f"Exception importing {self.pkg_path}") from err
ImportError: Exception importing custom_components.dwd_weather

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1067, in _get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 200, 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 "/config/custom_components/dwd_weather/__init__.py", line 14, in <module>
    from .connector import DWDMapData, DWDWeatherData
  File "/config/custom_components/dwd_weather/connector.py", line 81, in <module>
    CONF_MAP_HOMEMARKER_SHAPE_CIRCLE: dwdmap.MarkerShape.CIRCLE,
                                      ^^^^^^^^^^^^^^^^^^
AttributeError: module 'simple_dwd_weatherforecast.dwdmap' has no attribute 'MarkerShape'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 334, in _async_setup_component
    component = await integration.async_get_component()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1027, in async_get_component
    self._component_future.result()
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1019, in async_get_component
    comp = self._get_component()
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1078, in _get_component
    raise ImportError(f"Exception importing {self.pkg_path}") from err
ImportError: Exception importing custom_components.dwd_weather

Context

I run HA within podman, currently with the image ghcr.io/home-assistant/home-assistant:stable, the image id is 7fa0101862f6.

FL550 commented 1 day ago

I tried another approach with the import. Hopefully this will fix it.

HRDudeness commented 7 hours ago

Still an issue on 2.1.17. Version 2.1.13 was the last one working for me.

Logger: homeassistant.setup
Source: setup.py:334
First occurred: 13:07:42 (1 occurrences)
Last logged: 13:07:42

Setup failed for custom integration 'dwd_weather': Unable to import component: cannot import name 'MarkerShape' from 'simple_dwd_weatherforecast.dwdmap' (/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/simple_dwd_weatherforecast/dwdmap.py)
Traceback (most recent call last):
  File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/homeassistant/loader.py", line 1007, in async_get_component
    comp = await self.hass.async_add_import_executor_job(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/homeassistant/loader.py", line 1067, in _get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/homeassistant/util/loop.py", line 200, in protected_loop_func
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.pyenv/versions/3.12.3/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 "/mnt/dietpi_userdata/homeassistant/custom_components/dwd_weather/__init__.py", line 14, in <module>
    from .connector import DWDMapData, DWDWeatherData
  File "/mnt/dietpi_userdata/homeassistant/custom_components/dwd_weather/connector.py", line 33, in <module>
    from simple_dwd_weatherforecast.dwdmap import MarkerShape
ImportError: cannot import name 'MarkerShape' from 'simple_dwd_weatherforecast.dwdmap' (/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/simple_dwd_weatherforecast/dwdmap.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/homeassistant/setup.py", line 334, in _async_setup_component
    component = await integration.async_get_component()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/homeassistant/loader.py", line 1027, in async_get_component
    self._component_future.result()
  File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/homeassistant/loader.py", line 1019, in async_get_component
    comp = self._get_component()
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/homeassistant/loader.py", line 1067, in _get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/homeassistant/util/loop.py", line 200, in protected_loop_func
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.pyenv/versions/3.12.3/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 "/mnt/dietpi_userdata/homeassistant/custom_components/dwd_weather/__init__.py", line 14, in <module>
    from .connector import DWDMapData, DWDWeatherData
  File "/mnt/dietpi_userdata/homeassistant/custom_components/dwd_weather/connector.py", line 33, in <module>
    from simple_dwd_weatherforecast.dwdmap import MarkerShape
ImportError: cannot import name 'MarkerShape' from 'simple_dwd_weatherforecast.dwdmap' (/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/simple_dwd_weatherforecast/dwdmap.py)
Logger: homeassistant.util.loop
Source: util/loop.py:77
First occurred: 13:07:42 (1 occurrences)
Last logged: 13:07:42

Detected blocking call to import_module with args ('custom_components.dwd_weather',) in /home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/homeassistant/loader.py, line 1067: ComponentProtocol, importlib.import_module(self.pkg_path) inside the event loop; This is causing stability issues. Please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#import_module Traceback (most recent call last): File "/home/homeassistant/.pyenv/versions/3.12.3/bin/hass", line 8, in <module> sys.exit(main()) File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/homeassistant/__main__.py", line 209, in main exit_code = runner.run(runtime_conf) File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/homeassistant/runner.py", line 189, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/asyncio/base_events.py", line 674, in run_until_complete self.run_forever() File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/asyncio/base_events.py", line 641, in run_forever self._run_once() File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/asyncio/base_events.py", line 1987, in _run_once handle._run() File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/homeassistant/setup.py", line 165, in async_setup_component result = await _async_setup_component(hass, domain, config) File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/homeassistant/setup.py", line 334, in _async_setup_component component = await integration.async_get_component() File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/homeassistant/loader.py", line 1019, in async_get_component comp = self._get_component() File "/home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/homeassistant/loader.py", line 1067, in _get_component ComponentProtocol, importlib.import_module(self.pkg_path)
FL550 commented 6 hours ago

Too bad... With v2.1.14 I introduced a configurable map marker for the home position which uses the missing type.

The problem with this is, I can't reproduce this. I develop and test in the official container and I also use the integration in my own setup which is also inside a container.

If this error persists, I'll have to rewrite this.

HRDudeness commented 5 hours ago

Ok, I'm not using a container version. I have the bare metal install of HA Core on a DietPi system. Maybe there is some difference. Anything I could help with further debugging/testing?

Luminger commented 4 hours ago

I was able to dig up what was going wrong with my install:

For some reason, there's an outdated version of simple_dwd_weatherforecast present in /config/deps/lib/python3.12/site-packages/simple_dwd_weatherforecast/. The file pulled in is NOT /config/deps/simple_dwd_weatherforecast/dwdmap.py but rather /config/deps/lib/python3.12/site-packages/simple_dwd_weatherforecast/__pycache__/dwdmap.cpython-312.pyc.

I found it by putting a logging.getLogger(__name__).warn(dwdmap.__file__) directly below the dwdmap import found in connector.py.

I couldn't debug this in full but I'd guess this is an issue that's rooted in HACS. It installs dependencies directly into /config/deps but HomeAssistant actually wants to pull them from /config/deps/lib/python3.12/site-packages.

Edit: Copying /config/deps/simple_dwd_weatherforecas* into /config.deps/lib/python3.12/site-packages, after clearing the old version from that site-packages dir, fixes the issue.

Links2004 commented 4 hours ago

can confirm, running this in side the container and restarting gets it working:

rm -rf /config/deps/lib/python3.12/site-packages/simple_dwd_weatherforecast*
cp -r /config/deps/simple_dwd_weatherforecast* /config/deps/lib/python3.12/site-packages/
HRDudeness commented 3 hours ago

can confirm, running this in side the container and restarting gets it working:

rm -rf /config/deps/lib/python3.12/site-packages/simple_dwd_weatherforecast*
cp -r /config/deps/simple_dwd_weatherforecast* /config/deps/lib/python3.12/site-packages/

That did the trick! Had to adapt it for DietPi with HA Core, so it looks like this

rm -rf /home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/simple_dwd_weatherforecast*
cp -r /mnt/dietpi_userdata/homeassistant/deps/simple_dwd_weatherforecast* /home/homeassistant/.pyenv/versions/3.12.3/lib/python3.12/site-packages/
FL550 commented 38 minutes ago

@Luminger Thanks for debugging this!

I thought this might be a caching issue, but I wasn't aware it could be possible, that only some files are on an older version.

I'll check if there is some mechanism in HACS I can use to update the cache.