Fresh install and "No module named '_cec'

Hey ya. Just having a bit of difficulty setting up cec control. I initially had it configured through hassio no worries until I could not longer view the front end. I then installed hassbian 1.3, carried out sudo apt-get update, upgrade, dist-upgrade and reboot. After that I used hassbian-config to install samba - no worries. installed libcec through the same means no worries. ssh returns the right information through the echo command listed on the /components/hdmi_cec/ page. I can even monitor the cec bus through ssh no worries. After I added hdmi_cec: to my config yaml, restarted home assistant, the below error appeared in the log. So i adjusted my entry as such:

hdmi_cec:
  devices:
    TV: 0.0.0.0
    HT: 3.0.0.0

Same error is returned.

2017-09-17 03:25:47 ERROR (MainThread) [homeassistant.setup] Error during setup of component hdmi_cec
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/cec/__init__.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named '_cec'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/setup.py", line 194, in _async_setup_component
    component.setup, hass, processed_config)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/hdmi_cec.py", line 184, in setup
    adapter = CecAdapter(name=display_name[:12], activate_source=False)
  File "/srv/homeassistant/lib/python3.5/site-packages/pycec/cec.py", line 20, in __init__
    import cec
  File "/srv/homeassistant/lib/python3.5/site-packages/cec/__init__.py", line 21, in <module>
    _cec = swig_import_helper()
  File "/srv/homeassistant/lib/python3.5/site-packages/cec/__init__.py", line 20, in swig_import_helper
    return importlib.import_module('_cec')
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_cec'

To be honest I have no idea what any of this means. My level of experience with linux is basically copy and pasting from the web which I realise isn’t ideal at all. Can anyone shed any light on my problem?

Any news on this ? I have the exact same issue…
I’ve tried renaming __init__.py to cec.py (can’t remember where I foud this… On the libcec git I suppose), but then it fails a bit further, with the error module 'cec' has no attribute 'libcec_configuration'

No news as of yet, I decided to stop stressing myself out about this. Many other things to learn :slight_smile: I’d love a solution though.

I got it working !!! It was just missing _cec.so that was not linked over, as its one level up…
Just sudo cp -a /usr/local/lib/python3.5/dist-packages/_cec.so /srv/homeassistant/lib/python3.5/site-packages/ and voilà :slight_smile: (or just ln -s maybe…)

Hope it helps you.

5 Likes

Just swapped to Hassbian instead of Hassio and this fixed it for me too! Thanks so much for this comment!

Thanks, this worked for me on a hassbian install after installing/compiling the CEC lib.