Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup failed for custom integration 'miele': Unable to import component: No module named 'flatdict' #570

Open
WyriHaximus opened this issue Oct 23, 2024 · 17 comments
Labels
bug Something isn't working

Comments

@WyriHaximus
Copy link

WyriHaximus commented Oct 23, 2024

The problem

Integration doesn't start

Version of miele integration having the issue?

v2024.8.1

Version of Home Assistant Core having the issue?

2024.10.3

Anything in the logs that might be useful for us?

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

Setup failed for custom integration 'miele': Unable to import component: No module named 'flatdict'
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 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/miele/__init__.py", line 13, in <module>
    import flatdict
ModuleNotFoundError: No module named 'flatdict'

Additional information

Restarting HA doesn't fix this - refs #279

@WyriHaximus WyriHaximus added the bug Something isn't working label Oct 23, 2024
@astrandb
Copy link
Owner

Same problem has been reported recently, though it works for many thousands of users.
Is this a new install of the integration?
How are you running HA? HAOS, docker, core venv?

@WyriHaximus
Copy link
Author

Same problem has been reported recently, though it works for many thousands of users.

Whoops did I miss an existing issue?

Is this a new install of the integration?

Existing install but upgraded HA

How are you running HA? HAOS, docker, core venv?

Kubernetes so Docker

@astrandb
Copy link
Owner

Please see #568
It seems to be a problem with loading flatdict module in certain docker environments. Are there any errors or logs regarding flatdict when setting up the container? It is sometimes done in the container before you start HA.

@WyriHaximus
Copy link
Author

It seems to be a problem with loading flatdict module in certain docker environments. Are there any errors or logs regarding flatdict when setting up the container? It is sometimes done in the container before you start HA.

Haven't found anything yet in the logs besides what I shared. Did find flatdict in the deps directory so it is there. Will dig deeper into the logs

@astrandb
Copy link
Owner

astrandb commented Oct 23, 2024

You can add these lines to your config/configuration.yaml, restart HA and see if anything more is revealed.

logger:
    default: info
    logs:
        custom_components.miele: debug
        pymiele: debug

@WyriHaximus
Copy link
Author

Just rolled that out, the only things now I can find now are:

2024-10-23 22:12:00.250 INFO (SyncWorker_6) [homeassistant.util.package] Attempting install of flatdict==4.0.1
2024-10-23 22:12:08.819 INFO (SyncWorker_6) [homeassistant.util.package] Attempting install of pymiele==0.1.7

@astrandb
Copy link
Owner

Do you still get the stack trace as above?

@WyriHaximus
Copy link
Author

Yes that is still there

@jeanmoulart
Copy link

jeanmoulart commented Oct 30, 2024

Hey @WyriHaximus , got the same issue and could fix it by installing the missing libraries directly in the container

  1. docker exec -it homeassistant /bin/bash (replace homeassistant by the name of your container)
  2. pip install the requirements
  3. Restart HA
  4. Now configure Miele's integration.

Hope that works for you too.

@WyriHaximus
Copy link
Author

Thanks for the suggestion @jeanmoulart. Tried that, also removed the integration and both flatdict and pymiele from deps but essentially the same issue persists even tho HA will install both packages. The error is now just:

2024-10-30 21:08:36.912 ERROR (MainThread) [homeassistant.config_entries] Error occurred loading flow for integration miele: No module named 'flatdict'

@astrandb
Copy link
Owner

I have seen in the logs when building and starting HA in my development container that flatdict, and a few other libraries not related to this integration, are built as wheels. To me this indicates that the wheels binary package is not prebuilt in the distribution. It works for the absolute majority of users and I have no real clue what is missing in your setup.

@WyriHaximus
Copy link
Author

FWIW these are the install outputs:
image
image
(The flatdict version also seems off tho.)

I have seen in the logs when building and starting HA in my development container that flatdict, and a few other libraries not related to this integration, are built as wheels. To me this indicates that the wheels binary package is not prebuilt in the distribution. It works for the absolute majority of users and I have no real clue what is missing in your setup.

Is there a way to add the wheels package? IIRC the only thing I've been doing is update the docker image to whichever is the newest, and update packages when HACS tells me a new version is out.

@astrandb
Copy link
Owner

astrandb commented Nov 5, 2024

I have tried to install miele in a fresh HA container without any problems - everything works as expected.
Please try these commands and return the output.

# Access the container
docker exec -it homeassistant /bin/bash
# Show python version
python3 --version
#Show your installed flatdict version, if any...
pip show flatdict
#Uninstall flatdict
pip uninstall flatdict
# Install the required version manually
pip install flatdict==4.0.1

Restart HA and install Miele integration.

@WyriHaximus
Copy link
Author

First time going into the container:
image
Second time going into the container:
image
Third time going in, but first time after the restart:
image

Whats the default install location for this? It's not /config/deps I assume at this point.

Managed to get it work by doing the pip install for both flatdict and pymiele and then installing the integration. But that only works as long as the container is up. Running the latest 2024.11.x versions for both this integration and HA. Main question is why did it get switched from using /config/deps to the global install 🤔 .

@astrandb
Copy link
Owner

This problem is not caused by this integration. It is obviously something wrong with the way requirements are loaded for custom_components.
I know that there has been recent changes from pip to uv for loading and managing such requirements. There are also spurious reports from other integrations about similar problems.
I suggest that you ask in the Discord chat. Here is a link to a similar issue: https://discord.com/channels/330944238910963714/554842238073700352/1305373492245565460

@WyriHaximus
Copy link
Author

This problem is not caused by this integration. It is obviously something wrong with the way requirements are loaded for custom_components.

Agreed, and it's a nasty breaking change. Especially since HA is supposed to manage this for us.

I know that there has been recent changes from pip to uv for loading and managing such requirements. There are also spurious reports from other integrations about similar problems.

Having a similar issue with flightradar24 ye.

I suggest that you ask in the Discord chat. Here is a link to a similar issue: https://discord.com/channels/330944238910963714/554842238073700352/1305373492245565460

Thanks, I will have a look 👍 .

Do you prefer to keep this open until it's resolved at the root cause (assuming pip vs uv) or just close it?

@WyriHaximus
Copy link
Author

Seems they fixed something in the first major release of 2025, just upgraded to .2 and both this and the flight radar integrations just worked again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants