How to correctly install Python Package requirement in Custom Component?

Hi there, im currently trying my luck in setting up a custom component with a already released python package as requirement.

However, when trying to import from it in my __init__py i always get the error that it is not found. Therefore my guess is, that the requirement is actually not installed.

My Manifest looks like this:


{
  "domain": "test",
  "name": "Freenet Funk",
  "requirements": [
     "funkapi==0.1.5"
  ],
  "dependencies": [
  ]

and my __init__py like this:


DOMAIN = 'test'
def setup(hass, config):
    from funkapi import FunkAPI
    api = FunkAPI("USERNAME", "PASSWORD")
    currentTariff = api.getCurrentTariff()
    hass.states.set('test.world', 'TEST1234')
    hass.states.set('test.world2', currentTariff)
    # Return boolean to indicate that initialization was successful.
    return True

The error is the following:

2019-07-21 23:40:01 ERROR (MainThread) [homeassistant.setup] Error during setup of component test
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 156, in _async_setup_component
    component.setup, hass, processed_config)  # type: ignore
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/test/__init__.py", line 5, in setup
    from funkapi import FunkAPI
ModuleNotFoundError: No module named 'funkapi'

What did i do wrong?
How do i make hassio install the the pip3 funkapi?

anybody looking for the same… you need to import the python library first.

DOMAIN = 'test'
def setup(hass, config):
    import funkapi
    from funkapi import FunkAPI
    api = FunkAPI("USERNAME", "PASSWORD")
1 Like