Score:-3

AttributeError: module 'cec' has no attribute 'init' ubuntu 21.10 rpi4

td flag

When I run this script

#!/usr/bin/python3

import cec
import uinput
import time

u = uinput

KEYMAP = {
   0: u.KEY_ENTER,
   1: u.KEY_UP,
   2: u.KEY_DOWN,
   3: u.KEY_LEFT,
   4: u.KEY_RIGHT,
   9: u.KEY_HOMEPAGE,
  10: u.KEY_MENU,
  13: u.KEY_BACK,
  44: u.KEY_HOMEPAGE,
  68: u.KEY_PLAY,
  69: u.KEY_STOP,
  70: u.KEY_PAUSE,
  75: u.KEY_FASTFORWARD,
  76: u.KEY_REWIND,
 103: u.KEY_HOMEPAGE,
 113: u.KEY_BLUE,
 114: u.KEY_RED,
 115: u.KEY_YELLOW,
 116: u.KEY_GREEN
}

cec.init()
device = uinput.Device(KEYMAP.values())

print("Ready")
keystate = None

def onkey(event, key, state):
    assert event == 2
    global keystate
    if state == 0 and keystate is None:
        print("Got Key", key, "state", state)
        keystate = "down"
        device.emit(KEYMAP[key], 1)

    if state > 0:
        if keystate is None:
           print("Got key", key, "state", state)
           device.emit(KEYMAP[key], 1)

        print("Key {0} up after {1}".format(key, state))
        device.emit(KEYMAP[key], 0)
        keystate = None

cec.add_callback(onkey, cec.EVENT_KEYPRESS)

while True:
 time.sleep(9e9)

I get

Traceback (most recent call last):
  File "/home/mycroft/.config/autostart-scripts/cec-daemon.py", line 31, in <module>
    cec.init()
AttributeError: module 'cec' has no attribute 'init'

I have Ubuntu 21.10 rpi4 the libcec6 libcec-dev and python3-cec packages installed.

N0rbert avatar
zw flag
And what? From where you got this script? Was it tested for 21.10? For which Ubuntu version it was originally designed? Why do you think it should work on 21.10? How do you run it?
lnee avatar
td flag
The script was from plasma-bigscreen and no it was not intended for Ubuntu 21.10 how do I fix it
N0rbert avatar
zw flag
It still not reproducible. Could please add more details. Download/repository URL and steps to reproduce.
lnee avatar
td flag
It is the same one for Ubuntu arm64 Raspberry Pi `sudo apt install libcec6 libcec-dev python3-cec` then copy the script above and paste in to a file run the file with `python3 script.py`
N0rbert avatar
zw flag
Still not reproducible. Please add exact steps to reproduce to the question by editing it.
lnee avatar
td flag
how and have you tested the script on a pi?
N0rbert avatar
zw flag
I got error even on fresh amd64 docker container. Please show the original URL of the script which is included into the question body. From where it was copied/downloaded?
lnee avatar
td flag
it is from the plasma bigscreen img in /home/mycroft/.config/autostart-scripts/cec-deamon.py
lnee avatar
td flag
and test it on ubuntu rpi arm64
lnee avatar
td flag
ok so i remove the python3-cec deb package installed the cec pipy package and now every time i run the script the hdmi connection to the tv disconects
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.