Python support in libcec?

Would it be possible to include the libcec python support in the build? It would make scripting HDMI stuff a lot easier than either a manual build, or interacting with the command line client from a script.

libCEC is just a library. You should be able to grab the test / example code from here:

Sam

Sam,

That is indeed what I’m using. However, unless libcec is compiled with Python support:

osmc@osmc:~$ python
Python 2.7.9 (default, Mar  1 2015, 13:48:22) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cec
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named cec

I see – that makes sense now.

I compile it in a manner that optimises space. It’s quite simple to build an OSMC package (just clone the GitHub repo on to your OSMC device, cd package/libcec-osmc and run make). The rest will be done for you.

This may be the best way for now

Sam.

Thanks, and apologies for the daft question, but I’m unfamiliar with the OSMC build process, and I’m still having difficulty:

osmc@osmc:~/osmc/package/libcec-osmc$ make rbp2
sudo bash build.sh "rbp2"
Cleaning old source
Detected tarball source

[snip]

make: Entering directory '/mnt/package/libcec-osmc'
sudo bash build.sh "rbp2"
Building libcec
sudo rm -f *.deb > /dev/null 2>&1
sudo rm -rf files/usr > /dev/null 2>&1
sudo rm -rf files-dev/usr > /dev/null 2>&1
Updating sources
Sources updated successfully
Package libusb-dev is already installed in the environment
Package libudev-dev is already installed in the environment
Package autoconf is already installed in the environment
Package libtool is already installed in the environment
Package pkg-config is already installed in the environment
Package rbp-userland-dev-osmc is already installed in the environment

[snip]

Hunk #5 succeeded at 1169 (offset 2 lines).
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal  --output=aclocal.m4t
Can't exec "aclocal": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 326.
autoreconf: failed to run aclocal: No such file or directory
build.sh: line 34: ./configure: No such file or directory
make: *** No targets specified and no makefile found.  Stop.
make: *** No rule to make target 'install'.  Stop.
Error occured during build
Makefile:8: recipe for target 'rbp2' failed
make: *** [rbp2] Error 1
make: Leaving directory '/mnt/package/libcec-osmc'
Makefile:8: recipe for target 'rbp2' failed
make: *** [rbp2] Error 2

I’m not sure what I’m doing wrong, I think I have all the appropriate packages installed for build purposes.

Try installing build-essential first:

sudo apt-get update && sudo apt-get install build-essential

I don’t think there is anything else needed that isn’t automatically installed. (It’s a while since I’ve done a fresh install though so I could be wrong and have something else installed that I forgot I installed)

The package probably needs work actually. libCEC 3 is out now, so I probably need to update the build.

S

Hi, I’ve tried to enable python cec module with the following:
git clone https://github.com/osmc/osmc.git cd osmc/package/libcec-osmc/ make rbp2 sudo dpkg -i rbp2-libcec-osmc.deb sudo dpkg -i rbp2-libcec-dev-osmc.deb

Everything went ok but I still cannot get cec module in python:

`osmc@osmc-rpi2:/tmp/osmc/package/libcec-osmc$ python
Python 2.7.9 (default, Mar 1 2015, 13:48:22)
[GCC 4.9.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

import cec
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named cec`

I’m new to python programming and also to osmc / kodi development. Can you adviese what I did wrong?

Thank you!

Did you solve this python import issue?

EDIT: You can use following instructions:

Hi,

Anyone managed to compile libcec with Python support?

I’ve tried both methods:

  1. Cloning omsc/packages/libcec-osmc and make rbpi1
  2. Cloning Pulse-Eight/platform and Pulse-Eight/libcec with their instructions

Option 2 platform compiles ok, but libcec fails with #include <interface/vmcs_host/vc_cecservice.h> not found.

I feel that keeping with libcec-osmc is probably better since there are various other dependencies like rbp1-mediacenter-osmc

So far I have fixed a no architecture issue with only buidling cec, by adding test $(arch)x == armv6lx && echo "Architecture: armhf" >> $1 to common.sh

Apart from no architecture, Python support is always disabled in Option 1, but in Option 2 the Pulse-Eight install scripts picks it up -- Python support: version 3.4.2 (3.4). Is it forced to be off by the OSMC’s build.sh?

I’ve tried manually exporting the python environment variables without luck

Any help to force Python detection in the OSMC build process would be appreciated

This patch will likely do the trick:

diff --git a/package/libcec-osmc/build.sh b/package/libcec-osmc/build.sh
index 9876cb2..1809a42 100755
--- a/package/libcec-osmc/build.sh
+++ b/package/libcec-osmc/build.sh
@@ -30,6 +30,8 @@ then
        handle_dep "libtool"
        handle_dep "pkg-config"
        handle_dep "cmake"
+       handle_dep "python-dev"
+       handle_dep "swig"
        if [ "$1" == "rbp1" ]; then handle_dep "armv6l-libplatform-dev-osmc"; fi
        if [ "$1" == "rbp2" ] || [ "$1" == "vero" ] || [ "$1" == "vero2" ]; then handle_dep "armv7-libplatform-dev-osmc"; fi
        if [ "$1" == "rbp1" ] || [ "$1" == "rbp2" ]; then handle_dep "rbp-userland-dev-osmc"; fi

If there’s demand for it – I’ll get this included by default.

Thank you Sam, this brings me one step closer!

Including it by default would be great, but I had to change it to handle_dep "python3-dev" [one more variable to consider :smile:]

The next step would be to get the Python cec library to install (pip install cec), seems like it can’t find cec.h at the moment, but this needs some further investigation.

I see cec-utils depends on libcec2, do you repackage this at all, or is this the default package?

cec-utils are part of the osmc libcec package. I’m not keen on including a load of Python 3 stuff just for this package (nothing else needs it at the moment).

Sam

Looking at this again, and you don’t seem to need python3-dev. Maybe you were using Python 3 packages. This works for me:

-- Configured features:
-- Pulse-Eight CEC Adapter:                yes
-- Pulse-Eight CEC Adapter detection:      yes
-- lockdev support:                        no
-- xrandr support:                         no
-- Raspberry Pi support:                   no
-- TDA995x support:                        no
-- Exynos support:                         no
-- Amlogic support:                        yes
-- Python support:                         version 2.7.9 (2.7)

I’m happy to include support for python2.

Added in

You can fetch this version from staging

Hi I am not able to import cec. I installed on the new installation of osmc following packages: swig armv7-libplatform-dev-osmc armv7-libplatform-osmc rbp2-libcec-osmc rbp2-libcec-dev-osmc but i always get:

import cec
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named cec

What am I missing please?
Thx

Hello

I suspect this is because OSMC libraries are in the /usr/osmc directory. Find the Python path, and then append:

import sys
sys.path.append('/usr/osmc/FULL-PATH')

before your import statement

Thx for your help. You are right!

import sys
sys.path.append(‘/usr/osmc/lib/python2.7/dist-packages/’)
import cec

Great. Thank you for posting your solution. I am sure it will help other users.

If you have any cool projects or come up with something good, feel free to show it off in the General forum